unit-testing

Unit testing for safe publication.

How would you unittest a safe-publication guarantee in Java? To be concrete: I have a Cache interface that has a method getOrLoad(K key, ObjectLoader loader). Thing is, if a Cache cannot find an object for the given key, then it must load it from the ObjectLoader instance. However, the Cache is required to guarantee that the act of loa...

What are the best practices in your tests ?

I would like to know what are your practices when you test your classes. For example, I like to use inheritance, with my fixtures. Given two classes BaseClass, SubClass, I make two other classes BaseClassFixture and SubClassFixture (SubClassFixture is a sub class of BaseClassFixture). So I'm sure that I don't break code which use SubCla...

Unit tests framework for databases

I´m looking for a unit tests framework for database development. I´m currently developing for SQL Server 2000, 2005 and 2008. Do you know of any good frameworks with similar functionality as JUnit and NUnit? Perhaps it´s better to ask, what do you use to unit test your stored procedures and user defined functions? ...

Should I use "glass box" testing when it leads to *fewer* tests?

For example, I'm writing tests against a CsvReader. It's a simple class that enumerates and splits rows of text. Its only raison d'être is ignoring commas within quotes. It's less than a page. By "black box" testing the class, I've checked things like What if the file doesn't exist? What if I don't have permission on the file? What...

Unit Testing Framework for Oracle PL/SQL?

I've seen the question (and answer) when posed for MS SQL Server, though I don't yet know of one for Oracle and PL/SQL. Are there xUnit style testing frameworks for Oracle's PL/SQL? What are they? ...

Recovering from exceptions using CPPUnit

I have been using CPPUnit as a unit testing framework and am now trying to use it in an automated build and package system. However a problem holding me back is that if a crash occurs during the running of the unit tests, e.g. a null pointer dereferencing, it halts the remainder of the automation. Is there any way for CPPUnit to recove...

How to declare lambda event handlers in VB.Net ?

I believe the following VB.Net code is the equivalent of the proceeding C# code; however the VB.Net test fails - the event handling Lambda is never called. What is going on? VB.Net version - fails: <TestFixture()> _ Public Class TestClass <Test()> _ Public Sub EventTest() Dim eventClass As New EventClass Dim ev...

How do you refactor?

I was wondering how other developers begin refactoring. What is your first step? How this process (refactoring) differ if you refactor code which is not yours? Do you write tests while refactoring? ...

Comprehensive introduction to unit testing

Short backstory: I am a self-taught developer. This can lend to all manner of bad habits and misconceptions, but I am constantly learning and want to improve my skills. Insofar as I want to be a developer, I want to be a good developer. With that in mind... Unit testing is a mystery to me. I don't know what it is, how to do it, and so o...

How do I unit test a Java method which uses ProcessBuilder and Process?

I have a Java method which starts up a Process with ProcessBuilder, and pipes its output into a byte array, and then returns its byte array when the process is finished. Pseudo-code: ProcessBuilder b = new ProcessBuilder("my.exe") Process p = b.start(); ... // get output from process, close process What would be the best way to go ab...

Managing the maintenance burden of unit tests

Coding test-first, I find that perhaps 3/4 of my code is unit tests; if I were truly extreme, and didn't write a line of code except to fix a failing unit test, this ratio would be even higher. Maintaining all these unit tests adds a huge amount of inertia to code changes. Early on, I suck it up and fix them. As soon as there's pressu...

wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?

We need to write unit tests for a wxWidgets application using Google Test Framework. The problem is that wxWidgets uses the macro IMPLEMENT_APP(MyApp) to initialize and enter the application main loop. This macro creates several functions including int main(). The google test framework also uses macro definitions for each test. One of ...

What are some JavaScript Unit Testing and Mocking Frameworks you have used?

My main JavaScript framework is jQuery so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework. I am currently using QUnit for unit testing and Jack for mocking, but I am pretty new to the whole unit testing of JavaScript. Does anyone else have a bett...

Sharing State Amongst TestMethods in MSTest

How do I share state amongst TestMethods in MSTest. These tests would be run as Ordered Tests and in sequence. private TestContext testContext; public TestContext TestContext { get { return this.testContext; } set { this.testContext = value;} } [TestMethod] public void Subscribe() { ...

Selenium: wait_for_* and friends in Selenium RC ruby driver

Are there any implementations of all the nifty Selenium on Rails methods like wait_for_visible, assert_not_text_present, ... for the ruby driver of Selenium RC? If not, how would I go about implementing something like wait_for_visible? ...

Do you use Unit Testing in your professional projects?

We are about to start a new part of the project and there doesn't seem to be a lot of interest in unit testing (and it doesn't feel like they have experienced TDD). I believe it's nearly essential and it makes maintainance much easier. So what are your views? Thanks BTW: this is a language agnostic question, however the new project is ...

When do I use the TestFixtureSetUp attribute instead of a default constructor?

The NUnit documentation doesn't tell me when to use a method with a testfixturesetup en when to do the setup in the constructor public class MyTest { private MyClass myClass; public MyTest() { myClass = new MyClass(); } [TestFixtureSetUp] public void Init() { myClass = new MyClass(); } ...

Selenium RC: Run tests in multiple browsers automatically

So, I've started to create some Ruby unit tests that use Selenium RC to test my web app directly in the browser. I'm using the Selenum-Client for ruby. I've created a base class for all my other selenium tests to inherit from. This creates numerous SeleniumDriver instances and all the methods that are missing are called on each instan...

What is the most common mistake you make while writing unit tests?

What is the one most common mistake you make while writing unit tests? Coupling? Lack of cohesion? Try to test too much functionality at once? Not testing enough functionality? Post some example code if you have an example of that mistake ...

Should my unit tests be touching an API directly when testing a wrapper for that API?

I have some written a number of unit tests that test a wrapper around a FTP server API. Both the unit tests and the FTP server are on the same machine. The wrapper API gets deployed to our platform and are used in both remoting and web service scenarios. The wrapper API essentially takes XML messages to perform tasks such as adding/del...