unit-testing

Unit Testing Question and iBatis

We are developing a VB.Net Thick Client. Our Business Objects get filled from Services which make calls through iBatis to the DB. These BOs obviously hold information about the object in variables. I am curious on how far to take unit testing? Do you go as far as to do create a new object, fill all of the properties and then verify that...

How to mock abstract class with static members in Grails?

I need to mock a GrailsControllerClass interface. Instance should have a static variable defined. The problem is that MockFor and StubFor don’t give you an option for adding static members. So, I write my abstract class that extends GrailsControllerClass abstract class MyController implements GrailsControllerClass { static myDefiniti...

Has anyone got experience of using Nester?

All in the question really, but I'm looking for real world experience of using Nester beyond simple cash-machine sample programs. Does it really help improving the quality of tests? Do you end up with fewer bugs in production? Do you get many false alarms (say both paths through a condition can end up giving the same result for more c...

Conditionally ignoring tests in JUnit 4

OK, so the @Ignore annotation is good for marking that a test case shouldn't be run. However, sometimes I want to ignore a test based on runtime information. An example might be if I have a concurrency test that needs to be run on a machine with a certain number of cores. If this test were run on a uniprocessor machine, I don't think ...

Unit test a controller with custom model binder

In my application I have a custom model binder that I set to the DefaultBinder in the global.asax: ModelBinders.Binders.DefaultBinder = new XLDataAnnotationsModelBinder(); When writing unit tests for controllers I need to make sure the controller uses the custom model binder but I don't know how to do this. My test looks like this: ...

Why does instantiating a UIFont in an iphone unit test cause a crash?

I'm trying to unit test some iphone code that instantiates fonts. I've narrowed it down to the following crashing unit test: #import "test.h" #import <UIKit/UIKit.h> @implementation test - (void)testFonts { [UIFont systemFontOfSize:12]; } @end This crashes with the error: Test Case '-[test testFonts]' started. /Developer/Tools...

Unit Testing a class with an internal constructor

I have a class called "Session" which exposes several public methods. I'd like to Unit Test these, however in production I need to control instantiation of "Session" objects, so delegate construction to to a SessionManager class and have made the Session's constructor internal. I'd ideally like to test the Session class in isolation fro...

Feeding multiple pairs of files into a test method

I have a test method that tests the ToString() method of a class against known good outputs. /// <summary> ///A test for ToString ///</summary> [TestMethod()] public void ToStringTest() { string input = System.IO.File.ReadAllText(@"c:\temp\input2005.txt"); MyClass target = new MyClass(input); ...

Javascript Unit Testing Frameworks?

Can anybody recommend a Javascript unit testing framework. I've found JsUnit (http://www.jsunit.net/) and will start evaluating it. I just thought it would be good to get some input from the community. ...

How can I unit test views and authorization attributes of my asp.net mvc application in nUnit?

I'm at a point where I'd like to start writing unit tests for my MVC application. I've already figured out how to unit test the controller and I can unit test my underlying business libraries without any problem. I'm coming unstuck on a couple of items though: How do I unit test my views? That is, after a controller has returned the...

Using WatiN through MbUnit to test ASP .Net MVC web application

I am trying to apply some WatiN UI tests to my new ASP .Net MVC application, running the WatiN tests through MbUnit, but am having some difficulties. If I follow the instructions (exactly) on this page, then the google homepage loads, up the text is inserted, the search is done and the test passes. (no problem here). However, when I si...

RuntimeError: Declare either attr_protected or attr_accessible for User, but not both

Since a short time my rails applications yields the following runtime error in the test suite: RuntimeError: Declare either attr_protected or attr_accessible for User, but not both. This was probably introduced by an update to restful_authentication. But scanning the code for "attr_protected" only shows me it is never called. So why t...

C#: How would you unit test GetHashCode?

Testing the Equals method is pretty much straight forward (as far as I know). But how on earth do you test the GetHashCode method? ...

Write test results data to a Test Database in PHPUnit 3.4 release

I understand that the database log feature is supported in 3.3 version and not released in 3.4 is there any way I can use the database feature in 3.4 ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there are accepted/common file structures for this. Because my unit tests have several base classes in order to simplify project/customer speci...

C#: How do you write test cases for constructors and constructor overloads?

Say you have this shell of a class: public class Number { private int value; public Number() : this(0) {} public Number(int initialValue) : this(initialValue, 0, 100) {} public Number(int initialValue, int minimumValue, int maximumValue) { if (minimumValue > maximumValue) throw ...

What happened to Dojo DOH?

The Dojo Toolkit used to come with a testing facility called "Doh". It was in the /utils directory. Now when you download dojo-release-1.3.2 the /utils directory is nowhere to be found. Is Doh dead and gone? ...

Grails: How do you unit test a command object with a service injected into it

I am trying to test a Controller that has a Command object with data binding. The Command Object has a Service injected into it. But When I try test the command object the injected service method is never found as it is never "injected" Is there a way to mock a service inside a command object? Test method void testLoginPasswordInv...

How do I Fake UpdateModel for ASP.Net MVC?

I am trying to unit test a controller action that uses UpdateModel but I am not correctly mocking the HttpContext. I keep getting the following exception: System.InvalidOperationException: Previous method 'HttpRequestBase.get_Form();' requires a return value or an exception to throw. To mock the HttpContext I am using some thing ...

Is it a good idea to run unit tests of a library as part of the MSI that installs it?

I have a system that has many components interacting with each other. It occured to me to run tests as part of the installation process to make sure it works correctly in the client machine. Does this sound like a reasonable idea? Have you seen it done? What framework would you use to run the tests? ...