unit-testing

Identifying slow-running tests

In ruby's test/unit, the software indicates how long it takes for the tests to run, and the series of passes, errors and fails act like a pseudo-progress bar. Apart from using code profiling tools or running tests individually, is there an easy way of telling which test methods are fast and which ones are slow? ...

How do I decide if a failed system process like a database query or automated email merits an error message to the user?

I'm thinking through all the points in my PHP application where it performs some sort of system process like database queries, or sending out an email, and I'm wondering if at all these points I should be notifying a user when something goes wrong. There are so many points where an application can fall apart, that I'm having trouble dete...

Another one about measuring developer performance

I know the question about measuring developer performance has been asked to death, but please bear with me. I know the age old debate about how you cannot measure performance of developers, but the reality is, at our company there is a "need" to do that one way or another. I work for a relatively small company (small in terms of develop...

Assembly's App.Config is being ignored; Machine.config being read instead.

In running my VS2008 unit integration tests against my DAL, I have found that the assembly is reading machine.config instead of the assembly's app.config. Here's the rundown on the call stack: Unit Test Project has method calling into a DataLayer Project MyDataLayer class inherits from a base class. Method is called GetStuff() Base c...

Unit testing dependent methods

I would like to unit test a method on a class I have made, but this method requires another method to be called first. Example: // This would work MyClass myClass1 = new MyClass(mockDevice); myClass1.Run(myDatastructure); myClass1.Stop(); // This would throw an InvalidOperationException MyClass myClass2 = new MyClass(mockDevice); myCla...

changing constants for unit tests

Hi there, I'm writing some unit tests in cocoa for a data driven application. I've got a constants header file which defines a whole heap of variables including paths to the databases etc. I was wondering if it's possible to get all the classes to use a different set of constants which would link to a testing version of the database e...

TDD for a medium complexity method

I've been out of touch with TDD for some time, and am very rusty. I'd appreciate some suggestions on how to TDD the method described below. The method must find a web.config file in a user supplied application directory. It must then extract and return a connection string from that config file. It returns null if for any reason t...

Unit Testing the Use of TransactionScope

The preamble: I have designed a strongly interfaced and fully mockable data layer class that expects the business layer to create a TransactionScope when multiple calls should be included in a single transaction. The problem: I would like to unit test that my business layer makes use of a TransactionScope object when I expect it to. ...

Is there a plugin that integrates to CPPUnit with VS2008 or Eclipse CDT?

We have some projects that have CPPUnit tests that are build and run using an ant script to build them all (right now we're using Borland C++, but we're moving to VS2008). The problem is that the interface to run and see the result of tests is unpleasant (command prompt). It would be awesome to have them run inside eclipse or VS2008. I...

How to load web.config while using MS Test

I am testing some business object's Save() method. In order to save object, I need to read connection string from Configuration Manager. But all I get is null value. My settings are in web site web.config. How can I obtain during test runtime. Do I need additional configuration. ...

Unit Testing code that doesn't execute immediately

Hi, I am using C# 3.0 and NUnit. I'm wondering if there is a standard way to perform unit tests on code that executes after some amount of time. For example, I have a simple static class that I can register methods with, and have them be called n milliseconds later. I need to assure that code in the delegate methods is being called. Fo...

Testing Last Chance Exception Handling

I am trying to write a unit test to cover code found in our "last chance exception handler". When referring to last chance exception handling I am talking about event handlers of the events: Application.ThreadException AppDomain.CurrentDomain.UnhandledException More or less I am verifying that logs are being produced detailing the inf...

How do you customize exception handling behavior in JUnit 3?

I want to implement exception checking (like in JUnit 4) using JUnit 3. For example, I would like to be able to write tests like this: public void testMyExceptionThrown() throws Exception { shouldThrow(MyException.class); doSomethingThatMightThrowMyException(); } This should succeed if and only if a MyException is thrown. Th...

Do Visual Studio 2005 testing tools contain tools for mocking?

I'm working with VSTS 2005, and while the unit testing tools are fairly straightforward, I'm left wondering if there is any sort of support for mocking. I'd hate to have to do the mocking manually, because that leads to a lot of (mostly generated) boilerplate code. I have an edict from The Powers That Be, that a third-party mocking libr...

Rhino mocks change behaviour of stubs

Can I change the behaviour of a stub during runtime? Somthing like: public interface IFoo { string GetBar(); } [TestMethod] public void TestRhino() { var fi = MockRepository.GenerateStub<IFoo>(); fi.Stub(x => x.GetBar()).Return("A"); Assert.AreEqual("A", fi.GetBar()); fi.Stub(x => x.GetBar...

Stubbing objects with input arguments

So, I'm trying to stub a database connector in order to write tests for it. The problem is that the database connector is a pretty thin layer, and the queries to it are somewhat open-ended. I want my code to be able to ask for a variable from the database, and the connector should be OK with this. The signature for this call looks someth...

Mocking objects when using MSTest

I'm just getting started with MSTest (or at least the VS 2008 testing tools, is there a difference?) I'm wanting to test code that uses a session object. Obviously I don't have an HttpContext and I can't simply create one, so the code fails with a NullReferenceException. Is this code simply un-testable? ...

How to use Junit to test asynchronous processes

How do you test methods that fire asynchronous processes with Junit? I don't know how to make my test wait for the process to end (it is not exactly a unit test, it is more like an integration test as it involves several classes and not just one) ...

Unit Testing - definitions

Like anything else understanding the words makes it much easier to learn the language. Can anyone chime in with all the words used in unit testing with their definitions (ex. Mock, Fixture, etc. ) ...

using wsgiref.simple_server in unittests

I has some function like this one: URL = 'http://localhost:8080' def func(): response = urlopen(URL) return process(response) And i want to test it with unittest. I do something like this: from wsgiref.simple_server import make_server def app_200_hello(environ,start_response): stdout = StringIO('Hello world') star...