views:

346

answers:

4

Hello all,

I've inherited a load of Junit test, but these tests (apart from most not working) are a mixture of actual unit test and integration tests (requiring external systems, db etc).

So I'm trying to think of a way to actually separate them out, so that I can run the unit test nice and quickly and the integration tests after that.

The options are..

  1. Split them into separate directories.

  2. Move to Junit4 (from v3) and annotate the classes to separate them.

  3. Use a file naming convention to tell what a class is , i.e. AdapterATest and AdapterAIntergrationTest.

3 has the issue that Eclipse has the option to "Run all tests in the selected project/package or folder". So it would make it very hard to just run the integration tests.

2: runs the risk that developers might start writing integration tests in unit test classes and it just gets messy.

1: Seems like the neatest solution, but my gut says there must be a better solution out there.

So that is my question, how do you lot break apart integration tests and proper unit tests?

+2  A: 

I would move up to Junit4 just for having it :)

You could separate them into different test suites. I don't know how they are organised in Junit3 but it should be easy in Junit4 just to build up to test suites and put all the tests real unit tests in one of them and then use a second suite for the integration tests.

Now define a run configuration for both suites in eclipse and you can easily run a single suite. This suites also could be launched from a automated process allowing you to run the unit tests every time the source changes and maybe the integration tests(if they are really large) only once a day or once an hour.

Janusz
+2  A: 

I currently use separate directories due to organisational policy (and Junit 3 legacy) but I'm looking to transition to annotations myself now I'm on Junit 4.

I wouldn't be overly concerned about developers putting integration tests in your unit test classes - add a rule in your coding standards if necessary.

I'm interested to know what sort of other solutions there might be apart from annotations or physically separating the classes..

Steven Mackenzie
+2  A: 

We use Maven Surefire Plugin to run unit tests and Maven Failsafe Plugin to run integration tests. Unit tests follow the **/Test*.java **/*Test.java **/*TestCase.java naming conventions, integration tests - **/IT*.java **/*IT.java **/*ITCase.java. So it's actually your option number three.

In a couple of projects we use TestNG and define different test groups for integration/unit tests, but this is probably not suitable for you.

lexicore
+2  A: 

There's not one right answer. As you've explained, there are several ways to do it which will work. I've done both the file naming scheme and splitting things into different directories.

It sounds like splitting thing up into different directories might work better for you, and that seems a little clearer to me, so I'd lean towards that.

I don't think I would try annotations because that seems more fine-grained to me. Do you really want these two types of tests mixed together in the same file? I wouldn't.

ndp