unit-testing

Unit Tests Execute Really Slowly in Visual Studio 2008

I downloaded the MVC Storefront source code from Codeplex (http://mvcsamples.codeplex.com/) (the "Recommended Download", not from the most recent source code). If I click the "Run all tests in solution" button in VS 2008, the tests start to run, but they take about 3 seconds EACH, and there are 194 tests which would take about 10 minut...

Can someone explain the Visual Sudio 2008 Unit Test Generated Code for internal/private methods/properties?

Hi, My question is related to trying to understand the reason for the PrivateObject that VS automatically puts in the test and then uses to initialize the constructor for the generated accessor for the class with the private/internal property/method you are unit testing. Let me show you what I'm talking about... Imagine this simple cl...

Creating a mock URL referrer in ASP.Net MVC for Unit Testing

I'm currently testing my application and am stuck on trying to figure out how to create a custom fake URL referrer. I've tried to hard code it, but am getting an error that it is read-only. Here is what I've tried so far: fakeController.HttpContext.Request.UrlReferrer.AbsolutePath = "http://www.yahoo.com"; as well as, fakeControlle...

Unit Testing Machine Learning Code

I am writing a fairly complicated machine learning program for my thesis in computer vision. It's working fairly well, but I need to keep trying out new things out and adding new functionality. This is problematic because I sometimes introduce bugs when I am extending the code or trying to simplify an algorithm. Clearly the correct thin...

Unit Testing and PostSharp

I'm wondering what the best way to do this is... I'm interested in introducing PostSharp into one of my projects, but I'm not sure how to unit test classes marked with an attribute properly. For example: public class hello { [MyAspectThatDoesSomethingToTheDatabaseWhenThisMethodGetsCalled] public int omg(string lol) { /...

How to write a Mockist test of a recursive method

If I have a method that calls itself under a certain condition, is it possible to write a test to verify the behavior? I'd love to see an example, I don't care about the mock framework or language. I'm using RhinoMocks in C# so I'm curious if it is a missing feature of the framework, or if I'm misunderstanding something fundamental, or i...

Should we remove tests that are too simple to break during TDD

I have been trying to stick to the TDD approach. So I have made some tests and they all fail. Now I am implementing. But now that I am implementing I have seen that the methods are too simple to fail. In particular I have implemented the observer pattern and all that happens is that I notify all the registered observers. So use a for eac...

Maintainable Unit Tests

I recently finished a project using TDD and I found the process to be a bit of a nightmare. I enjoyed writing tests first and watching my code grow but as soon as the requirements started changing and I started doing refactorings I found that I spent more time rewriting / fixing unit tests than I did writing code, much more time in fact....

Injecting dependencies into tests

Usually when using dependency injection, unit (and other) tests are responsible for creating/mocking dependencies of the system-under-test and injecting them. However, sometimes the test itself has dependencies, or needs to inject dependencies into the SUT that it can't itself create. For example, when testing classes which interact wit...

Unit Testing a Class That Uses the File System

I have a class that outputs a simple report file. It reads some record ID numbers from an XML file: each one used for finding a matching record stored in a database. It then writes out each record's details to a CSV file. I am wondering - what is the best way to organise it so that it is easy to test, yet follows the principles of encap...

EJB3Unit save-function doesn't really save my entity

Hello, I am doing tests on an ejb3-project using ejb3unit session bean test. The following test will fail with the last assertNotSame() check. public void testSave() { Entity myEntity = new Entity(); myEntity.setName("name1"); myEntity = getBeanToTest().save(myEntity); assertNotSame("id should be set", 0l, myEntity.getId());...

Is there a XML to Linq Generator?

I have an XML file that I want to base some unit tests off of. Currently I load the XML file from disk in the class initialize method. I would rather have this xml generated in the test instead of reading the file from disk. Are there any utilities that will automatically generate the linqtoxml code to generate a given XML file? Or a...

Getting "InternalError: no such savepoint" with PostGIS in Django even when using TransactionTestCase

Just added geoDjango and moved the database over to PostGIS. I have a bunch of Unit tests that pass individually, but when run together I get an IntenalError the database being grumpy between the tests. The model that's getting used in these tests is a django.contrib.gis.db model. The tests even inherit from TransactionTestCase instead o...

ASP.Net MVC unit test exception

Hello, I'm using the Moq framework to do my unit testing. I'm following some really useful instructions outlined here to help me mock the httpcontext, specifically for the purposes of testing the url referrer: http://my6solutions.com/post/2009/08/18/Mocking-HttpContext-in-ASP-NET-MVC.aspx Everything seems to compile fine, however whe...

Simplified asserts in OCUnit

I just started jusing OCUnit and find the asserts a bit cumbersome. In JUnit I can write a test to compare numbers like below. This test will obviously fail, but this shows the nice, simple assert I can write for two numbers and the feedback I get: "expected <2> but was <3>" with very little code. What I tried so far i XCode is: Wh...

Unit Testing Advice - how to unit test your .asmx

I'm just about done creating a web service that will be consumed by a non .NET internal custom system. I would like some advice on the best way to setup test classes and methods over an .asmx (best practices, how to test the calls, what not to do, etc.) specifically in a .NET 3.5 environment. I will be using NUnit to do this testing. ...

Junit (3.8.1) testing that an exception is thrown (works in unit test, fails when added to a testSuite)

I'm trying to test that I'm throwing an exception when appropriate. In my test class I have a method similar to the following: public void testParseException() { try { ClientEntitySingleton.getInstance(); fail("should have thrown exception."); } catch (RuntimeException re) { assertEquals( "<...

Some unit tests fail in automated Team Build task

I have an odd situation. I have a suite of unit tests that pass on my dev machine. They pass on the build machine if run from visual studio. But 5 of them reliably fail during the automated build. There is nothing noteworthy about the ones that fail that I can see (and I've stared at them a long time). Anyone seen anything like this? ...

How to organize integration tests?

When writing unit tests, I usually have one test class per production class, so my hierarchy will look something like that: src/main -package1 -classA -classB -package2 -classC src/test -package1 -classATests -classBTests -package2 -classCTests However when doing integration tests the organization becom...

xUnit false positive when comparing null terminated strings

I've come across odd behavior when comparing strings. First assert passes, but I don't think it should.. Second assert fails, as expected... [Fact] public void StringTest() { string testString_1 = "My name is Erl. I am a program\0"; string testString_2 = "My name is Erl. I am a program"; Assert.Equal<string>(testString_1, t...