unit-testing

How should I Test a Genetic Algorithm

I have made a quite few genetic algorithms; they work (they find a reasonable solution quickly). But I have now discovered TDD. Is there a way to write a genetic algorithm (which relies heavily on random numbers) in a TDD way? To pose the question more generally, How do you test a non-deterministic method/function. Here is what I have ...

How can I run unit tests for just the source files which have changed?

Is there a way I can get ant to run the unit tests just for the java classes it builds? For example, if MyClass.java is out of date, ant will build MyClass.class. After that I want it to also run MyClassTest and MyClassTestSuite if they exist. It doesn't have to be based on a naming convention. I'd be fine with using annotations or a...

How to configure SQLite to run with NHibernate where assembly resolves System.Data.SQLite?

I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite and have the configuration set up as: Dictionary<string, string> properties = new Dictionary<string, string>(); properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver"); properties.Add("dialect", "NHibernate.Dia...

Writing unit tests for network related classes

I have a class that is responsible for network communication. I would like to have a unit test for it. Here is where I'm stuck in order to write a test for it i have to implement a server to communicate with but that in turn will require its own test. How do you write tests for a class such as this? ...

How are you able to Unit Test your controllers without an IoC container?

I'm starting to get into Unit Testing, Dependancy Injection and all that jazz while constructing my latest ASP.NET MVC project. I'm to the point now where I would like to Unit Test my Controllers and I'm having difficulty figuring out how to appropriately do this without an IoC container. Take for example a simple controller: public c...

Django unit testing with date/time-based objects

Suppose I have the following Event model: from django.db import models import datetime class Event(models.Model): date_start = models.DateField() date_end = models.DateField() def is_over(self): return datetime.date.today() > self.date_end I want to test Event.is_over() by creating an Event that ends in the futur...

Do you check HttpVerbs in your unit tests?

Hi, While looking at the unit tests that come with the standard ASP.MVC Web Project template, I noticed that these do not test whether or not a proper HttpVerbs attribute is set on each action method. It's very easy to test this with reflection, but the question is whether or not it It's worth the effort. Do you check HttpVerbs in you...

Unit testing NHibernate UserTypes

Does anyone have a good approach towards unit testing their UserTypes? By way of example, I have an object in my model called DateRange, which has a DatePoint start and DatePoint end. In addition to making range type operations available for two DateTimes, these objects let me adjust the precision for the task at hand (i.e., Day, Hour, ...

Adding unit testing to an existing asp.net web forms application

I have an existing asp.net webforms application that I would like to add some unit testing to but am unsure of exactly how to go about it. The application is database driven with functionality I guess you could compare to an advanced forum. Logic, data access and presentation are seperated for the most part. What methods should I be te...

How can I define multiple associated objects using Factory Girl?

The Factory Girl docs offer this syntax for creating (I guess) parent-child associations... Factory.define :post do |p| p.author {|a| a.association(:user) } end A post belongs to a User (its "author"). What if you want to define a Factory to create Users, that have a bunch of Posts? Or what if it's a many-to-many situation (...

What can be alternative metrics to code coverage?

Code coverage is propably the most controversial code metric. Some say, you have to reach 80% code coverage, other say, it's superficial and does not say anything about your testing quality. (See Jon Limjap's good answer on "What is a reasonable code coverage % for unit tests (and why)?".) People tend to measure everything. They need co...

Is there a neater way of testing calls to mocked methods for each item in a list

This is an example of a pattern I've encountered a lot recently. I have a method to be tested that takes a List and may invoke some other method(s) for each item in the list. To test this I define an Iterator with the expected call parameters and a loop in the JMock expectations to check the call is made against each item of the iterator...

Dictionaries with volatile values in Python unit tests?

I need to write a unit test for a function that returns a dictionary. One of the values in this dictionary is datetime.datetime.now() which of course changes with every test run. I want to ignore that key completely in my assert. Right now I have a dictionary comparison function but I really want to use assertEqual like this: def my_fu...

Rails assert that form is valid

What's the best practices way to test that a model is valid in rails? For example, if I have a User model that validates the uniqueness of an email_address property, how do I check that posting the form returned an error (or better yet, specifically returned an error for that field). I feel like this should be something obvious, but as...

Visual Studio 2008 Professional Build Process

I would like to accomplish two things during my build process: Run unit tests - I have a Test Project with my unit tests. I would like to run all of these tests on build and receive a notification if the build fails validation. Merge web.config files - I have 3 different environments with configuration details specific to each. I wou...

How do I setup this(Moq Setup)

Hi I want to test my part of code that returns the users password question. So I have made a mockup of the Membership provider using MOQ. I don't think I need to show you the actual code just the test part of it. // Arrange var membershipMock = new Mock<MembershipProvider>(); membershipMock.Setup(m => m.GetUser(...

Testing for ImportErrors in Python

We're having a real problem with people checking in code that doesn't work because something's been refactored. Admittedly, this is partly because our developers don't really have any good tools for finding these kinds of mistakes easily. Are there any tools to help find ImportErrors in Python? Of course, the correct answer here is "y...

How to test materialized view in java

Is there any way to write automated tests for materialied views using Hibernate framework? I don't know how to make it work. My first approach was to use DBMS_MVIEW.REFRESH stored procedure. But, it is not what I need - all test data is commited after refreshing the view. Is there any different way to test the view? ...

Can I do this in my unit tests?

Hi I am not sure what I should be doing here. Should I be hardcoding all the values in or should I have them in a CONST variables. Everything I seen seems to hard code the values in so I am not sure. Like this is what I was doing now. Say in my controller I had a validation test to check if the user tries to submit a form with a blan...

How do I tell when I need to write my own Interface and Wrapper for unit testing?

Hi I am still confused of when I have to make a wrapper and interface to fake my tests. Like in a book I am reading about MVC the author uses the Moq framework. So the author first makes a IFormAuthentication interface. Writes some methods there and then makes a WrapperClass that implements these methods and then writes the actual co...