com.github.peterwippermann.junit4.parameterizedsuite.SuiteForSingleParameter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parameterized-suite Show documentation
Show all versions of parameterized-suite Show documentation
JUnit 4 provides the commonly known Runners "Suite" and "Parameterized". However, as of today there is no Runner implementation that combines the features of both. This library provides a custom Runner for this purpose.
package com.github.peterwippermann.junit4.parameterizedsuite;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import org.junit.runners.model.Statement;
import com.github.peterwippermann.junit4.parameterizedsuite.util.BlockJUnit4ClassRunnerWithParametersUtil;
/**
* This extension of {@link Suite} is used by {@link ParameterizedSuite} to fork a run of the
* suite's children for a single parameter.
*
* @author Peter Wippermann
*
*/
public final class SuiteForSingleParameter extends Suite {
private String suiteName;
private Object[] singleParameter;
public SuiteForSingleParameter(RunnerBuilder runnerBuilder, Class> forkingSuiteClass, Class>[] classes, String suiteName, Object[] singleParameter)
throws InitializationError {
// By passing "forkingSuiteClass" (which is the forking ParameterizedSuite), the JUnit
// framework will build the internal testClass attribute from the ParameterizedSuite and not
// from this virtual, forked Suite.
// This way @Before/After/Class can be evaluated.
super(runnerBuilder, forkingSuiteClass, classes);
this.suiteName = suiteName;
this.singleParameter = singleParameter;
}
protected String getName() {
return this.suiteName;
}
protected Statement classBlock(RunNotifier notifier) {
return BlockJUnit4ClassRunnerWithParametersUtil.buildStatementWithTestRules(childrenInvoker(notifier), getTestClass(), getDescription(),
getActiveParameter());
}
protected Object[] getActiveParameter() {
return this.singleParameter;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy