unit-testing

Unit testing with Spring framework singleton beans

It’s a general consensus that Singleton is bad for unit-testing. But what about having an IoC container like the Spring framework to control your beans which are singletons by default? Is using those beans in your classes also considered bad for unit testing the same way singleton is? ...

Skip unit test if csv file not found

Hi, I have a number of unit tests which rely on the presence of a csv file. They will throw an exception if this file doesn't exist obviously. Are there any Gallio/MbUnit methods which can conditionally skip a test from running? I'm running Gallio 3.1 and using the CsvData attribute [Test] [Timeout(1800)] [CsvData(FilePath = TestDataF...

Python, unittest: Can one make the TestRunner completely quiet?

Is there a way to make unittest.TextTestRunner completely quiet, meaning that it never prints to output on its own? Even at verbosity=0 it prints results when done. The thing is that i want to process the TestResult object returned by the runner before anything is printed. ...

.Net Unit test compile error - The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided.

We've got a generic class which contains a private class which uses the outer class's generic type parameter. Example: public class Foo<T> { private class Bar : IGrouping<Guid,T>{ } } The problem is that we get a compile error in a unit test project which states "The Type or method has 2 generic parameter(s), but 1 generic ar...

How to unit test a form with a captcha field in django?

Hello all, I would like to unit test a django view by sumitting a form. The problem is that this form has a captcha field (based on django-simple-captcha). from django import forms from captcha.fields import CaptchaField class ContactForm(forms.forms.Form): """ The information needed for being able to download """ las...

How to unit test a class using System.Windows.Threading.Dispatcher

How do I unit testing a class which makes use of System.Windows.Threading.Dispatcher? I am following the MVVM pattern in the setting of WPF. As part of this I am creating a DispatchingBlah class following the pattern used for DispatchingQuoteSource that I saw in this video (see 1:06:16 ish). I want to test that my class has queued the...

Imported files not recognized in OCUnit

Hi, I am doing unit testing on my iPhone app using OCUnit on XCode 3.2.3, and iOS 4.0. I have successfully set up my testing environment to pass and fail basic tests appropriately, but when I import my own files (in this case, "UserAccount.h", it fails to compile and tells me: "_OBJC_CLASS_$_UserAccount", referenced from: It then says...

Javascript unittesting frameworks

Hi all, I am loooking for a javascript unittesing framework and trying to decide if I should go with JSunit or not. My goal is to have the unittests run with my CI, possibly using a JSunit server that is running headless. From people's experience, is this a good idea? Are there better frameworks that you would recommend for my goals, ...

c# Unit Test for a method which is calling Console.ReadLine()

Hi everyone first post here. I want to create a unit test for a member function of a class called ScoreBoard which is storing the TOP5 players in a simple game. The problem is that the method i am creating test for(SignInScoreBoard) is calling Console.ReadLine() so the User can type his name. public void SignInScoreBoard(int steps...

Spring + Maven: separate property files for unit tests and integration tests

I'm using Spring 2.5.6 and building my project with Maven 2.2.1. We use PropertyPlaceholderConfigurer beans in Spring to load up properties for configuring things like the database. Pretty standard stuff. We also have two different sets of tests: unit tests and integration tests. I would like to be able to use different property files ...

How do I mock static methods in a class with easymock?

Suppose I have a class like so: public class StaticDude{ public static Object getGroove() { // ... some complex logic which returns an object }; } How do I mock the static method call using easy mock? StaticDude.getGroove(). I am using easy mock 3.0 ...

Rails: Unable to initialize has_many :through association from within unit test using model class name

I've been struggling to understand why I can easily use seeds.rb to create new Users and their default associations, but when running individual a unit test causes errors. I've tried to get around calling 'Role' as it causes errors in the unit test. I am relatively new to unit testing, but have been using Rails for several years alread...

Using the connectionstring in an nunit test

Hi, we use the nunit.exe application to run our (integration)test Now i experience the problem that the connectionstring is not picked up from the app.config from the dll where the testcode is in. That sounds logical because the nunit.exe is the starting app and not the test dll (it used to work when i started the tests from the visua...

Why is RhinoMocks throwing an InvalidOperationException at my test?

This is a test I am currently working on: (Edited according to Lees answer) [Test] public void AddLockClassWithNullNameShouldCallInsertOnSessionWithEmptyString() { LockClass lockClass = new LockClass { Id = ValidId, Name = null }; using ( mockRepository.Record() ) { sessionFactory.CreateSession(); LastCall.Retur...

NUnit - Asserting Exception and properties

Hi, I'd like to Assert that an exception is being thrown and then check some of the properties of the thrown exception. I was under the impression that I could do something like the following: ICommand command = CreateCommandObj(); Assert.That( () => command.DoWork(), Throws.TypeOf<ArgumentException>(), ...

Unit testing private functions in Silverlight

Does anyone know how to test private functions in a Silverlight Unit Test project? The *_Accessor objects don’t seem to be available that are their in a normal unit testing project. ...

RSpec on Controller and Stubbing

I am pretty new to using rspec and am trying to write my tests for my controllers. I have this controller (I am using mocha for stubbing): class CardsController < ApplicationController before_filter :require_user def show @cardset = current_user.cardsets.find_by_id(params[:cardset_id]) if @cardset.nil? flash[:notice]...

Using phpunit, what should I do to have the code coverage report include the tests run via selenium?

The coverage information is created by xdebug but instead of the inclusion into the coverage report, it creates a file with the information for every test in the webroot of the application. I use the following setup: class SeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { public function __construct($name,array $data = a...

Is there a way to use w3c-validator as a local instance using either a session cookie or using username and password?

I would like to integrate the usage of w3c-validator into unit testing. Is there a way to get around authentication to do this? ...

Unit Tests for method returning xmldocument

I need to create a unit test for a method that returns an xmldocument. What should I be validating in such a case? The method checks a database and creates an xmldocument and sends back the data to the client. Should I look if the xmldocument returned has all expected xml tags? or should I have a Expected.xml file and match the xmldocum...