eventhorizon
eventhorizon

Reputation: 3377

Webservice functional/integration test with Junit

The question aims to find a better solution than mine.

I have the following REQUIREMENTS for my integration tests:

  1. Each integration test is implemented in a single test class.
  2. The methods in a test class have to be executed in order.
  3. Each method is one step of the integration/functional test.
  4. If a test method fails all other test methods in the test class have to be skipped - because it does not make sense to find subsequent errors.

MY SOLUTION looks like this:

I just inherit every test class from my abstract test class:

package myPackage;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestWatcher;

public abstract class FailFastTest {

    private final static List<Class<?>> FAILED_CLASSES = new CopyOnWriteArrayList<Class<?>>() ;

    private final Class<? extends FailFastTest> thatClass = this.getClass();

    @Rule
    public final TestWatcher onFailedRule = new TestWatcher() {
        protected void failed(Throwable e, org.junit.runner.Description description) {
            FAILED_CLASSES.add(thatClass);
        };
    };

    @Before
    public final void beforeMethod() {
        final boolean failed = FAILED_CLASSES.contains(thatClass);

        if(failed) {
            System.out.println(thatClass + " FAILED. Aborting test.");
            org.junit.Assume.assumeTrue(!failed);
        }
     }
}

Does anybody have a better idea? My PROBLEM: I cannot run such a test class multiple times in parallel because of the classname signals the skipping...

NO! It is not a duplicate! I try to write functional tests which use different (web-)services in a specific order. The Question "How do I test a servlet?" is quite different!

Anyway. I switched to TestNG. TestNG supports all requirements I have and works like charm. I do not need my glue code any longer!

Upvotes: 1

Views: 121

Answers (0)

Related Questions