unit-testing

How to programmatically start a WPF application from a unit test?

Problem VS2010 and TFS2010 support creating so-called Coded UI Tests. All the demos I have found, start with the WPF application already running in the background when the Coded UI Test begins or the EXE is started using the absolute path to it. I, however, would like to start my WPF application under test from the unit test code. That...

Regression Tests Through Gated Check-ins

Do we think gated check-ins + automated builds + unit tests are able to provide sufficient confidence in changes to shared assembly code to make deployment in the GAC an attractive option? Does anybody have any real life setups that provide this level of confidence? Follows on from this question: Revisiting GAC Installations Thanks, D...

Django doctests in views.py

The Django documentation on tests states: For a given Django application, the test runner looks for doctests in two places: The models.py file. You can define module-level doctests and/or a doctest for individual models. It's common practice to put application-level doctests in the module docstring and model-level doctests in...

Hibernate sessionFactory rebuilt for each unit test (using spring framework)

I'm using Spring's AbstractTransactionalDataSourceSpringContextTests for my persistence unit tests and my problem is my tests are too slow: 1 method=5s, and each additional method is at least another second. I've over 300 db tables so a slow startup is perhaps understandable. However I've gone through the logs and one of the surprising t...

Run Visual Studio Unit Tests vs Run ReSharper Unit Tests, differences?

So I have been running into all kinds of interesting problems in VisualStudio 2008 when running Unit Tests. Such as, when running Visual Studio Unit Tests some tests are failing together but passing individually. This is happening because some class level variables in that test class is being reused in the Unit Tests. Now normally I w...

asp.net MVC ModelState is null in my Unit Test. Why?

ModelState is always returning null in my unit tests. I was hoping someone could tell me why. Given the following controller: public class TestController : Controller { public ViewResult Index() { return View(); } } My test gets null for ModelState with this test: public void ModelState_Is_Not_Null() { TestCon...

How to write a unittest for importing a module in Python

Hi, What is the pythonic way of writing a unittest to see if a module is properly installed? By properly installed I mean, it does not raise an ImportError: No module named foo. ...

Do unit tests on the 'live' database in settings.py while using Django's 'manage.py test'

If you've got a database setup in Django, how can you have the TestRunner use the 'live' database (per the DATABASE_* settings in settings.py) instead of running them on the ephemeral test database. For example, I'd like to run the following test on the live database that's specified in settings.py: import unittest from example import...

Is it reasonable to enforce that unit tests should never talk to a live database/webservice?

My team continues to find more and more value in the unit tests we write. We don't generally unit test the data access layers of our applications, as they don't contain "logic". In my experience we've run into significant performance issues and non-reproducible errors as a result of letting developers write unit tests that talk to live d...

Create new test suite with Rspec or extend current Test::Unit setup?

So I'm extending a friend's project and he's done all the development with TDD using Test::Unit I use Rspec in all my projects and want to avoid having to learn a new tool. Is it bad practice to have 2 separate test suites, one in Test::Unit and one in Rspec? I've also considered using Shoulda to extend Test::Unit to sort of feel like ...

How to repeat a test case without duplicate code?

Hi, I'm using shoulda with Ruby on Rails, and I have the following test cases: class BirdTest < Test::Unit::TestCase context "An eagle" do setup do @eagle = Eagle.new end should "be able to fly" do assert_true @eagle.can_fly? end end context "A Crane" do setup do @cra...

What is a good way to test that a Java method is synchronized?

I have several classes that implement some interface. The interface has a contract, that some methods should be synchronized, and some should not, and I want to verify that contract through unit tests for all the implementations. The methods should use the synchronized keyword or be locked on this - very similar to the synchronizedColl...

How to implement or emulate an "abstract" OCUnit test class?

I have a number of Objective-C classes organized in an inheritance hierarchy. They all share a common parent which implements all the behaviors shared among the children. Each child class defines a few methods that make it work, and the parent class raises an exception for the methods designed to be implemented/overridden by its children...

How to avoid MIXED_DML_OPERATION error in Salesforce tests that create Users

Sometimes in Salesforce tests you need to create User objects to run part of the test as a speciifc type of user. However since the Salesforce Summer 08 update, attempts to create both User objects and normal objects (such as Accounts) in the same test lead to the following error: MIXED_DML_OPERATION, DML operation on setup object ...

Rhino Mocks stubs and mocks are only good for interfaces?

Is it correct that Rhino Mocks stubs and mocks are only good for interfaces, not concrete classes? I spent quite a time trying to make this piece of code working. What I did not expected is that stabbed pubSubClient will always call Send method from the class. That method has some dependencies and throws exception. [Test] public void Te...

How do I run a set of nUnit tests with two different setups?

(Sorry for the unclear title, please edit it if you can come up with a better one) I wish to run the same tests over two different data stores, I can create the data stores in the Setup() method. So should I have a super class that contains all the tests and an abstract SetUp() method, then have a subclass for each data store? Or is t...

Testing: I *want* to test web.config

I want to do some unit testing on one of my projects. This is a web project, and there will only be one copy of this program running aside from development copies. I want to write some unit tests that will use the web.config. I understand that ordinarily, a tester would stub out this external dependency because he wants to test the co...

Unit Testing Error - "Unable to get type" "Error: Could not load type" "from assembly"

I am getting this error with my new unit test: Unable to get type MyTestProject.MyTestClass, MyTestProject. Error: Could not load type 'MyTestProject.MyTestClass' from assembly 'MyTestProject'.. I have other tests in the project that were working just fine and now they are all showing a similar error message. If I run the test in Resh...

Unit Testing and VS 2008

I am familiar with jUnit. What unit testing framework is very popular for VS? ...

Should class methods accept parameters or use class properties

Consider the following class public class Class1 { public int A { get; set; } public int B { get; set; } public int GetComplexResult() { return A + B; } } In order to use GetComplexResult, a consumer of this class would have to know to set A and B before calling the method. If GetComplexResult accesses man...