unit-testing

Should Dispose methods be unit tested?

I am using C#. Is it advised to unit test dispose methods? If so why, and how should one test these methods? ...

Mocking the "save" method on domain classes

I'm having hard time mocking the save instance method in my unit tests in Grails 1.3.3. I've created a simple domain class named Person, it has one property (nullable) called "name". package tutorial class Person { String name static constraints = { name nullable: true } } In my test I'm trying to do something ...

Mocking HttpRequest in ASP.NET 4.0

I've seen a lot of similar threads but none that actually address my particular situation. I'm writing unit tests in ASP.NET 4.0 web application (ASP.NET Forms, not MVC). There are several spots in the code where I call the ServerVariables collection to call variables like REMOTE_ADDR. Since my unit tests do not actually initiate HttpRe...

Is it a good practice to write classes that typically have only one public method exposed?

The more I get into writing unit tests the more often I find myself writing smaller and smaller classes. The classes are so small now that many of them have only one public method on them that is tied to an interface. The tests then go directly against that public method and are fairly small (sometimes that public method will call out to...

Is it possible to unit test View's in CodeIgniter?

I'm using TOAST and it's doing a great job testing models... but what about views? ...

How to test an anonymous inner class that calls a private method

We have a bunch of classes that listen for events from the server and then respond to them. For example: class EventManager { private Set<Event> cache = new HashSet<Event>(); private EventListener eventListener = new EventListener() { void onEvent(Event e) { if (e instanceof MyEvent || e instanceof YourEvent) ...

mocking Request.Files to test empty file upload

I am trying to unittest a file upload but seem to be missing something. The controller contains this fairly standard block in the httpPost handler: foreach (string file in Request.Files) { var postedFile = Request.Files[file] as HttpPostedFileBase; if (postedFile.ContentLength == 0) continue; var fileName = "~/Uplo...

Using repository pattern in ASP.NET MVC with a SQL Server DB; how to mock repository so its unit testable without breaking OOD

I've been learning the ASP.NET MVC framework using the Apress book "Pro ASP.NET MVC Framework" by Steven Sanderson. To that end I have been trying out a few things on a project that I am not that familar with but are things that I thing I should be doing, namely: Using repository pattern to access my database and populate my domain/bus...

WP7 - ViewModel Unit Testing

I had a unit test project for my windows phone 7 app ViewModels using the April Tools Refresh and everything worked fine. I just updated to the beta tools and now I can't get the test project to add a reference to nunit. The error I receive is "Reference can not be added because it was not built using the Windows Phone runtime. Win...

Mocking a method and returning different results

I've got a method that's mildly complicated and needs to be very well tested. Secret sauce stuff. Ok, maybe not that cool, but I'm not 100% sure how to go about getting these things setup. This sort of stems from my previous question here. I haven't used rhino mocks so I'm still bad/unaware of the syntax, so feel free to make a ton o...

Open source alternative for TestDrive.net 'Visual Studio add in' for unit testing?

Hello I searched about this in SO and dint find a post on this. Since TestDriven.net is ONLY free for personal use, is there any other open source visual studio add in available for running NUnit test cases? Thank you. NLV ...

How to mock property/internal value of UIApplication?

I'm writing unit tests. And I cannot test one function, because it calls keyWindow UIWindow* window = [UIApplication sharedApplication].keyWindow; And keyWindow returns nil (I don't have any window). But I need to return anything, but nil. I used category to manually set keyWindow value, but this didn't work @interface UIApplication...

Unit Test Fails -- Why?

Hi, I have the following test in my unit test suite: STAssertEquals(0, [[newUnit itemsWithinBasketFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count], @"A unit with no items should return 0 when asked for items in place within a date range. (count=%i)", [[newUnit itemsWithinBasketFrom:[NSDate...

Unit testing legacy program written in C

I am maintaining a server application written in C many years ago. It has very few unit tests (cxxtest) and I am thinking about developing more. I read on the subject of unit testing C programs in the last days and tried a few things also. The right thing to do appears to be to include the .c file containing the function to test from m...

scons and "Test Anything Protocol" integration

I'm looking to scons-ify a project that has a Test Anything Protocol testing framework. Can anyone give me direction on prior work here or smoothly integrating the two? (Is there a native python TAP harness, should I shell out to a custom Test::Harness wrapper, etc.?) Thanks. ...

MVC unittest: access Project.Tests base dir

How do I access the current project directory in a unitest? I would like to test a controller that accesses user generated files. In the controller, I use Server.MapPath("~/Uploaded") which works great. However, that doesn't work for the unittest. I understand that I probably have to mock HttpContext.Server.MapPath but to what? Do I ...

NSLog statements aren't working while unit tests are running

Hi all, I am unit testing my app in xcode, but for some reason I can't see any printouts in the debugger console from the NSLog() statements in my implementation files. Why would this be? And how do I get my darned printouts?? Thanks ...

unit testing - per test code coverage for java

We use use junit for unit testing our java code. Today we use cobertura to get coverage numbers. It does not have an easy way of getting per test coverage number. Is there a tool to get per test code coverage - commercial/free? (cobertura has a patch to get per test coverage numbers, out of date with latest cobertura). ...

Unit Testing for NSError's

Hallo, I am trying to set up some unit tests for code that accepts an *NSError as an argument. If there is a validation problem, then the object is not saved and the NSError condition is set. My method is: - (BOOL)validateConsistency:(NSError **)error { ... code omitted for brevity ... if (errorCondition == YES) { N...

Unit testing my wcf services

I am hoping there is a better way to do this. Do I really have to wrap each method of my wcf service into an interface in order to use it? I don't think my fellow developers are going to buy into this because of the amount of time it takes... there must be a better way! ...