unit-testing

Expect exceptions in nUnit without the ExpectedException attribute

Hi, I have methods with more than one parameter that are guarded against bad input by throwing ArgumentNullExceptions and ArgumentExceptions whenever any parameter is null. So there are two obvious ways to test this: One test per Parameter using the [ExpectedException] attribute One test for all parameters using multiple try{} catch b...

TDD: Which methods do you expose for unit testing?

There is one aspect of TDD which I never fully understood. Suppose somebody asked you to implement a simple Stack object. If you've done your design properly, you will come to a very minimal and clean API. Suppose: push(), pop() and isEmpty(). Anything more than that is over-killing the demand, and allowing the user too much room to mes...

Unit testing in C++

How do I get started doing unit testing in C++ ? I have used Junit when coding in Java and found it very useful. Is there something similar in C++ ? What do you recommend ? ...

Unit testing - videos or podcasts

I am looking for podcasts or videos on how to do unit testing. Ideally they should cover both the basics and more advanced topics. ...

How to make an existing public API testable for external programmers using it?

I have a C# public API that is used by many third-party developers that have written custom applications on top of it. In addition, the API is used widely by internal developers. This API wasn't written with testability in mind: most class methods aren't virtual and things weren't factored out into interfaces. In addition, there are som...

Unit-testing C++ templates

I've used function and class templates in implementation of my libraries. So far I've just instantiated a template in the library unit-tests (CppUnit), and then proceeded to test it almost like any other normal class or function. Recently I've been planning to add some templates also to the library APIs. Good interface is of course the ...

What a good strategy or tool to unit test database conversions? (Not unit testing databases, but the conversion)

I am working on a project where we are converted the old system to a brand new system. We are currently converted from the database of the old system to the database of the new system, and a team is working on creating a set of maps and transforms to run at the end of development to convert over the old system. I would like to implemen...

Verifying protected abstract methods are called using Moq

Suppose I have the following class: public class TestBase { public bool runMethod1 { get; set; } public void BaseMethod() { if (runMethod1) ChildMethod1(); else ChildMethod2(); } protected abstract void ChildMethod1(); protected abstract void ChildMethod2(); } I also have the class public class Chi...

Testing Data Access Persist Methods

Hi guys Just wondering if anyone has any ideas on how to test ones data access methods. I have found testing retrieval data access methods is much easier because i can just mock out the ExecuteReader and return a populated dataTable.CreateDataReader(). By doing this I can test to see if my object is populating correctly if a result set ...

Unit testing on code that uses the Database

I'm interested to know what approach people are taking in developing automated unit tests that exercise the database Do you Install a QA database (known-starting point) before the test suite is run. OR Do you build database stub that stand-in whenever a database call occurs? EDIT: Related question, but not a duplicate, though quite...

How to test a hash function?

Is there a way to test the quality of a hash function? I want to have a good spread when used in the hash table, and it would be great if this is verifyable in a unit test. EDIT: For clarification, my problem was that I have used long values in Java in such a way that the first 32 bit encoded an ID and the second 32 bit encoded another ...

Which Unit test framework and how to get started (for asp.net mvc)

I'v never done unit testing before, but now I am willing to give it a try. What framework is best for starters? Pros and Cons what should i read before i begin any coding? Books/Articles/Code/Blogs is there any opensource "sample projects"? I will be usign it with asp.net mvc/C#. ...

How to write an automated test for thread safety

I have a class which is not thread safe: class Foo { /* Abstract base class, code which is not thread safe */ }; Moreover, if you have foo1 and foo2 objects, you cannot call foo1->someFunc() until foo2->anotherFunc() has returned (this can happen with two threads). This is the situation and it can't be changed (a Foo subclass is...

Cause of an unexpected behaviour using JUnit 4's expected exception mechanism?

I am trying to test that a particular method throws an expected exception from a method. As per JUnit4 documentation and this answer I wrote the test as: @Test(expected=CannotUndoException.class) public void testUndoThrowsCannotUndoException() { // code to initialise 'command' command.undo(); } However, this code fails t...

Problem with VSTS UnitTesting. Can't supply C++ DLLs.

Hi I am using VSTS Unitesting platform. I am trying to test a method which got references to assemblies which in turn contain DllImport to C++ DLLs. In order for it to work I need to copy C++ DLLs to reside on the same directory the EXE and DLLs are running. Of course when I use the same code with Unittest I also need to supply those...

creating unit tests (semi-)automatically?

Is there a framework that supports generating some standard unit tests from annotations? An example of what I have in mind would be: @HasPublicDefaultConstructor public class Foo { } This would obviously be used to automatically generate a unit test that checks whether Foo has a default constructor. Am I the only person who thought o...

Strategies for Using Mock Objects when Unit Testing DAOs

I am curious what strategies folks have found for unit testing a data access class that does not involve loading (and presumably unloading) a real database for each test method? Are you using mock objects to represent the database connection? If so, are you required to pass the mock object into every method-under-test, and thus forcing t...

How to unit test winforms applications

Thanks to ASP.NET MVC framework, it became possible to unit test web applications. But how do you unit test windows forms applications? ...

Do you write your unit tests first, after a bit of coding or not at all?

I was wondering when most people wrote their unit tests, if at all. I usually write tests after writing my initial code to make sure it works like its supposed to. I then fix what is broken. I have been pretty successful with this method but have been wondering if maybe switching to writing the test first would be advantageous. ...

Tool for testing using parameter permutations

I remember there existed a testing program/library that will run your code and/or unit tests, creating all kinds of permutations of the parameters (null values, random integers, strings and so on). I just can't remember what it was called and searching google doesn't seem to come up with anything. I know it was created for Java code and...