Skip to content

BinaryTweed/quarantining-test-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quarantining-test-runner

Build Status

A JUnit test runner that loads the test class and optionally specified classes in a separate ClassLoader. This means that static members will effectively be reset between each test class, as new versions of those classes are loaded.

Maven dependency

<dependency>
  <groupId>com.binarytweed</groupId>
  <artifactId>quarantining-test-runner</artifactId>
  <version>0.0.3</version>
</dependency>

Check the latest version on Maven Central.

To use

import com.binarytweed.test.Quarantine;
import com.binarytweed.test.QuarantiningRunner;

@RunWith(QuarantiningRunner.class)
@Quarantine({"com.binarytweed", "com.example.ClassName"})
public class MyIsolatedTest {
...
  1. Annotate your test class with @RunWith(QuarantiningRunner.class).
  2. Use @Quarantine("com.example") to specify patterns which separately-loaded class names should start with.
  3. Optionally specify @DelegateRunningTo(SomeCustomRunner.class) to have QuarantiningRunner use another Runner implementation. By default it uses org.junit.runners.JUnit4 (which currently extends BlockJUnit4ClassRunner).

How it works

The test class and runner class are loaded using QuarantiningUrlClassLoader. When either of these two classes reference a class that hasn't yet been loaded, QuarantiningUrlClassLoader will be used to load the requested class.

It will delegate loading classes that do not match the patterns provided by @Quarantined to its parent ClassLoader; patterns that do match are loaded by itself. Because each test run uses a a distinct instance of QuarantiningUrlClassLoader, any classes it loads are distinct from any previous runs.

About

JUnit Runner that loads specified classes in a separate ClassLoader, which can be handy when depending on third party frameworks which make use of static members.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages