Skip to content

Commit

Permalink
Added ParallelInnerTestClassesSuite -- resolves MichaelTamm#23
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudbahaa committed Oct 11, 2023
1 parent 40a8a33 commit f069862
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ The JUnit Toolbox provides some useful classes for writing automated tests with
* [WildcardPatternSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/WildcardPatternSuite.html) -- A replacement for the JUnit runners `Suite` and `Categories`, which allows you to specify the children classes of your test suite class using a wildcard pattern. Furthermore you can include and/or exclude multiple categories.
* [ParallelSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/ParallelSuite.html) -- An extension of the `WildcardPatternSuite`, which executes its children classes concurrently using several worker threads. Although it extends `WildcardPatternSuite` you are not forced to use a wildcard pattern, you can also list the children class using the `@SuiteClasses` annotation known from JUnit.
* [InnerTestClassesSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/InnerTestClassesSuite.html) -- A replacement for the JUnit runner `Enclosed` which executes all inner test classes of the class annotated with ` @RunWith(InnerTestClassesSuite.class)`. In contrast to the `Enclosed` runner provided by JUnit it detects if an inner class is actually a test class and ignores all other inner classes.
* [ParallelInnerTestClassesSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/ParallelInnerTestClassesSuite.html) -- A replacement for `InnerTestClassesSuite` which executes its children classes concurrently using several worker threads.

`ParallelRunner`, `ParallelParameterized`, and `ParallelSuite` share a common Fork-Join-Pool. You can control the maximum number of worker threads by specifying the system property `maxParallelTestThreads`. If this system property is not set, there will be as many worker threads as the number of processors available to the JVM.
`ParallelRunner`, `ParallelParameterized`, `ParallelSuite` and `ParallelInnerTestClassesSuite` share a common Fork-Join-Pool. You can control the maximum number of worker threads by specifying the system property `maxParallelTestThreads`. If this system property is not set, there will be as many worker threads as the number of processors available to the JVM.

# How to use it #

Expand All @@ -24,6 +25,30 @@ If you use [Maven](http://maven.apache.org), add the following dependency to you

# Release Notes #

## Version 2.5 (for Java 8) and Version 1.12 (for Java 6) ##

* New runner `ParallelInnerTestClassesSuite` which runs all inner test classes of the class annotated with `@RunWith(ParallelInnerTestClassesSuite.class)`. In contrast to the `Enclosed` runner provided by JUnit, it detects if an inner class is actually a test class and ignores all other inner classes. In contrast to `InnerTestClassesSuite` it executes its children classes concurrently using several worker threads. run Example:
```
@RunWith(InnerTestClassesSuite.class)
public class LoginBeanTests {
public static class UnitTests {
@Test
public void test1() { ... }
}
@Configuration
public static class IntegrationTestsConfig { ... }
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = IntegrationTestsConfig.class)
public static class IntegrationTests {
@Test
public void test2() { ... }
}
}
```

## Version 2.4 (for Java 8) and Version 1.11 (for Java 6) ##
* [WildcardPatternSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/WildcardPatternSuite.html) can now handle wildcard patterns starting with "../" (fixes [#16](https://github.com/MichaelTamm/junit-toolbox/issues/16))
* Fixed edge case where too many threads were created when using one of [ParallelRunner](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/ParallelRunner.html), [ParallelParameterized](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/ParallelParameterized.html), or [ParallelSuite](//michaeltamm.github.io/junit-toolbox/com/googlecode/junittoolbox/ParallelSuite.html) contributed by Till Klister
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.googlecode.junittoolbox;

import org.junit.experimental.runners.Enclosed;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;

/**
* Runs all inner test classes of the class
* annotated with <code>&#64;RunWith(ParallelInnerTestClassesSuite&#46;class)</code>.
* It executes its children classes concurrently. You can specify the maximum number
* of parallel test threads using the system property <code>maxParallelTestThreads</code>.
* If this system property is not specified, the maximum number of test threads
* will be the number of {@link Runtime#availableProcessors() available processors.}
* In contrast to the {@link Enclosed} runner provided by
* <a href="http://junit.org/" target="_blank">JUnit</a>,
* it detects if an inner class is actually a test class
* and ignores all other inner classes.
* Example:<pre>
* &#64;RunWith(ParallelInnerTestClassesSuite.class)
* public class LoginBeanTests {
*
* public static class UnitTests {
* &#64;Test
* public void test1() { ... }
* }
*
* &#64;Configuration
* public static class IntegrationTestsConfig { ... }
*
* &#64;RunWith(SpringJUnit4ClassRunner.class)
* &#64;ContextConfiguration(classes = IntegrationTestsConfig.class)
* public static class IntegrationTests {
* &#64;Test
* public void test2() { ... }
* }
* }
* </pre>
*/
public class ParallelInnerTestClassesSuite extends InnerTestClassesSuite {
public ParallelInnerTestClassesSuite(Class<?> klass, RunnerBuilder runnerBuilder) throws InitializationError {
super(klass, runnerBuilder);
setScheduler(new ParallelScheduler());
}
}

0 comments on commit f069862

Please sign in to comment.