unit-testing

Unit test proper data structure creation

How would one test whether data structure built properly? I'm implementing kind of modified radix tree, and been wondering how do you check if your data structure builds up correctly. Consider a tree of TreeNode {String, Int} nodes. You always want to append new child to deepest node of value equal to 0, as in following example: Root,...

Unit Testing Domain Services Against a Real Database

I was wondering what approaches others might have for testing domain services against a database? I already have a series of mock repositories that I am able to use in the domain services for testing the domain services themselves. Part of the construction of these mock repositories is that they build out sample aggregates and associat...

VS2008 Unit test "Pending" and the test cannot be completed.

I'm using VS2008 (with windows XP). Every time I try to run a unit test it stays on "Pending" and the test cannot be completed. I tried to reinstall VS, but it didn't help. Any advice? ...

Interfaces and unit tests - always white-box testing?

I have finally got in my mind what worried me about Dependency Injection and similar techniques that should make unit tests easier. Let's take this example: public interface IRepository { void Item Find(); a lot of other methods here; } [Test] public void Test() { var repository = Mock<IRepository>(); repository.Expect(x => x.Find()...

Is there really any difference between NUnit, MSTest, etc.?

Is there really any difference between NUnit, MSTest, etc.? For example, can any of them detect what code changed since the last build and only run the affected unit tests? Do any of them have tight integration into database setup/rollback for integration-style tests? Do any of them allow for scripting TCP ports or web services to tes...

Mocking vs. faking, when to use what?

Can anyone come up with a guidelines kind of stuff, suggesting the ideal scenarios when to go for mocking or faking (setting up the essentials manually). Bit confused with the approach? ...

C# Asyn. Socket Programming

Is it possible to unit test the Asyn. socket programming (using c#)? Provide some sample unit test code. ...

Is summary necessary in unit test method

Since the naming of a unit test method makes its purpose more meaningful, is it necessary to add a summary to a unit test method? Example: /// <summary> /// Check the FormatException should be thrown when a give country data line contains a invalid number. /// </summary> [TestMethod] public void FormatException_Should_Thrown_When_Parse...

[C++] How should I organize test cases in my project?

Hi, I have a project that looks like this: xdc/ hubactions/ hubconnection.cpp hubconnection.h uiinterface/ readme uiconnection.cpp uiconnection.h ... uiactions/ readme connectaction.cpp connectaction.h quitaction.cpp quitaction.h ... utils/ parser.cpp parser.h ... N...

Issues mocking the MVC ControllerContext request

I'm pretty new to testing and mocking and i am trying to write a test that will ensure that my validation logic is setting ModelState errors correctly. What I'm seeing is that the controller.ControllerContext.HttpContext.Request is set the first time I check it but every time after that the Request is null. This is causing a null r...

How to do unit test on remote store procedure

I'm facing to do the unit test on the data access layer, all the data access layer call database through the store procedure. I plan to create a clean database used for unit testing, but I found most of store procedure will remote call the other database, I've no idea on how to unit test this kind of store procedure, should I create all ...

How do I unit test a method that is expecting an object to be updated via a reference?

I'm having trouble unit testing a method that changes some properties of a reference type that is passed to it. As an example, let's say I have a class called Policy. Policy policy = new Policy(); policy.Status = Active; I then pass this policy to the policy manager in order to inactivate the policy. policyManager.InactivatePolicy(p...

Remove signing of dll in Visual Studio with script

We have a C# solution with ca. 55 projects, including test projects. Since part of the project is sharepoint all dll's are signed. We would like to run unit tests with code coverage. We then get the problem the code coverage cannot instrument signed dll's. We therefore need to unsign the dll's, run the tests, and then resign them. Wit...

How do I unit test overloaded functions?

So I have a class that looks something like the following: public class MyClass { DatabaseDependency _depend; public MyClass(DatabaseDependency depend) { _depend = depend; } public string DoSomething(DBParameter database) { var result = _depend.GetResults(database, ...); string response...

Testing for required behaviour vs. TDD

In the article Test for Required Behavior, not Incidental Behavior, Kevlin Henney advises us that: "[...] a common pitfall in testing is to hardwire tests to the specifics of an implementation, where those specifics are incidental and have no bearing on the desired functionality." However, when using TDD, I often end up writing tes...

Removing a dependency in a constructor using PHPunit

While trying to get a legacy codebase under test, I've come across an object that does the following: class Foo { public function __construct($someargs) { $this->bar = new Bar(); // [lots more code] } } Bar in this instance has a constructor that does some Bad Things e.g. connecting to a database. I'm tryi...

Verifying event registration using Moq.net

I'm developing an asp.net (classic) application trying to implement the MVP pattern using this example. In trying to unit test my presenter and using the following pattern, the psuedocode for which looks like so //base view interface public interface IView { event EventHandler Init; event EventHandler Load; bool IsPostBack...

Resharper Unit Test Runner significantly slower than NUnit console

Resharper Unit Test Runner runs significantly slower than nunit-console or nunit gui. For example, 3800 tests take just over 60 seconds via nunit-console, but those same tests take over 5 minutes to run in Resharper Unit Test runner. Why such a significant difference? Since our test code base has grown significantly, this is really ...

List of Mock (Moq) objects - best practices/simplification.

Consider the following: new SUT(null, null, new List<IObjectBeingMocked>() { mockObjectOne.Object, mockObjectTwo.Object }) My SUT (System Under Test) needs a list of objects as the third parameter. These need to be mocks as I've set some expectatioins on these. How would I clear it up so that I can remove the need to call .Object on ...

What is needed in the HttpContext to allow FormsAuthentication.SignOut() to execute?

I am trying to write a unit test for our log out method. Amoung other things it FormsAuthentication.SignOut(). However, it throws a System.NullReferenceException. I've created myself a mock HttpContext (using Moq) but it is obviously missing something. My mock context contains: A mocked HttpRequestBase on Request A mocked HttpRespo...