unit-testing

ReSharper Unit Test Runner - TestCase

I like using the ReSharper unit test runner, but it doesn't support the TestCase attribute that was added in NUnit 2.5. Is there any hack to get round this? I can obviously use another test runner, but I like the ReSharper one. ...

What is the community-preferred Ruby unit testing framework?

In the Java space, JUnit is predominately used and in .NET I believe nUnit is very popular. Is a community agreed upon unit testing framework for the Ruby world? Background: I ask because I am new to Ruby and want to practice TDD at same time as I learn Ruby. So far I've only played with Test::Unit. ...

is there anyway to use TestCase.assertEqual() outside of a TestCase?

I have a utility class that stores methods that are useful for some unit test cases. I want these helper methods to be able to do asserts/fails/etc., but it seems I can't use those methods because they expect TestCase as their first argument ... I want to be able to store the common methods outside of the testcase code and continue to u...

Unit testing a Swing component

I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like CurrentDirChanged etc. in following manner: private void fireCurrentDirectoryChanged(final IFile dir) { if (SwingUtilities.isEventDispatchThread()) for...

Simple syntax for testing Validation errors

I'm looking for clean and short code to test validations in Rails Unittests. Currently I do something like this test "create thing without name" do assert_raise ActiveRecord::RecordInvalid do Thing.create! :param1 => "Something", :param2 => 123 end end I guess there is a better way that also shows the validation messa...

Should I force exceptions to test them ?

i have this method in my data access class and i have a unit test to make sure it does work properly, but my test doesn't test the exception so my question is should i create a new test to force the exception to be raised or should i just trust that the catch block will work just fine in case of an exception ? is it worth the effort ? h...

Unit testing a Java multi-threaded network app

I am writing a Java multi-threaded network application and having real difficulty coming up with a way to unit test the object which sends and receives communication from network clients. The object sends out a message to a number of clients and then waits for responses from the clients. As each client responds, a dashboard-style GUI i...

How do I use PyMock and Nose with Django models?

I'm trying to do TDD with PyMock, but I keep getting error when I use Nose and execute core.py from command line: "ERROR: Failure: ImportError (Settings cannot be imported, because environment variable DJA NGO_SETTINGS_MODULE is undefined.)" If I remove "from cms.models import Entry" from the unit test module I created, everything work...

When unit testing, do you have to use a database to test CRUD operations?

When unit testing, is it a must to use a database when testing CRUD operations? Can sql lite help with this? Do you have to cre-create the db somehow in memory? I am using mbunit. ...

Unit Testing Real World Example

I have been asked to assist in coding a number of MS Unit Tests for a number of object to object mappings. Can anyone advise what level of testing is appropriate to test the mapping functionality? Shown below is some (non production) sample code. public class Foo { public enum FooType { Active, Deleted, Open, Closed ...

Why doesn't Visual Studio break on exceptions when debugging unit tests?

When I attempt to debug a unit test that fails because of an unhandled exception in my code, I expect Visual Studio to break on the unhandled exception so I can inspect the code and isolate the problem. Instead, the IDE instantly exits debug mode and the test is listed as "Failed", leaving me to consult the test result's stack trace to ...

How to handle exception in a background thread in a unit test?

I'm writing a unit test suite to test a TCP/IP communication library. As I'm using BeginAcceptClient and EndAcceptClient, the messages are received in a background thread. After a message is received, I perform some assertions on it, but if any assertion fails, the VSTestHost.exe crashes. I googled a bit and found out its the fact the...

Generate Manager Report from Unit Tests (Visual Studio)

Is it possible to generate a report from Visual Studio 2008's integrated unit tests? Say, one you hand off to an account manager to include in an invoice for the client. One that looks say 10% as good as this? I ask because Rob Conery made a great video about using BDD to develop applications. And within it, he uses a 3rd party fra...

How to preserve an in memory datastructure to later use it in a Unit test

Hi. In my code, I am occasionally passed various byte arrays and such. Also, they may be managed objects. I would like to preserve those memory structures so that I can write test cases against the concrete examples. My standard approach is to hit the breakpoint, use the debugger to find the various values and then either new them up o...

Is there a recommended way to set environment variables for CUnit tests?

We want to use CUnit to test a shared library that we have developed. The shared library is loaded via the standard Solaris LD_PRELOAD mechanism where it uses an environment variable to remap a string containing a file path to a new date and time based on the file path. Initial testing will use a single value for the environment variab...

Unit Testing Stubbed Method

Given this class: public class OrderService { public OrderService(IOrderLogger log) { this.log = log; } private readonly IOrderLogger log; public void PurgeOrder(Order order) { ... var action = new LogAction("foo","bar"); log.Action(action); } } And this test: [Fact] public void Purg...

How do you test a referenced class that performs internal operations?

How would I test the following code? Public Sub SetSerialIdForDevice() Try Dim component As Object = container.getComponentRef("componentInterface") If component IsNot Nothing Then component.SetupDeviceSerialID(container.serialNumbers) Else serialfound = False ...

reusing test suites with multiple implementations?

I'm testing with nUnit. I have a suite of tests that run against my IFoo interface; the Test Fixture Setup determines which IFoo implementation to load and test. I'm trying to figure out how to run the same suite against a list of IFoo implementaions, but don't see any way to test all implementations without manually modifying the Setu...

How to avoid setup code duplication with record-replay mode of Rhino Mocks?

This is a test suite that is green using Rhino Mocks. [SetUp] public void BeforeEachTest() { _mocksRepo = new MockRepository(); _mockBank = _mocksRepo.StrictMock<IBank>(); //_mockPrinter = _mocksRepo.StrictMock<IPrinter>(); _mockPrinter = _mocksRepo.DynamicMock<IPrinter>(); _mockLogger = _mocksRepo.Str...

ASP.net MVC RTM Test naming conventions

I am working on an asp.net mvc application and writing my unit tests BDD style. Eg. GetResource_WhenResourceFileExists_ShouldReturnResources() But when I am writing tests for my controllers, I usually have two Methods with the same name. One without parameters for get requests and one with for posts. Does anybody have a good naming...