Package gw.test
Class Suite<T extends Suite>
- java.lang.Object
-
- junit.framework.TestSuite
-
- gw.test.Suite<T>
-
- All Implemented Interfaces:
junit.framework.Test
public class Suite<T extends Suite> extends junit.framework.TestSuiteThis Suite class streamlines and simplifies the standard JUnit TestSuite. It can be used in one of two ways: you can add individual tests to the Suite via the withTest() methods, or you can use the filter methods to pare down the tests that are found on the current classpath.
-
-
Field Summary
Fields Modifier and Type Field Description private TestExecutionManager_executionManagerprivate java.util.List<IDirectory>_gosuClassSearchPathprivate java.util.List<Predicate<IFile>>_iFileFiltersprivate java.util.List<IDirectory>_javaClassSearchPathprivate boolean_logErrorInfoprivate java.util.List<java.lang.String>_modulesprivate java.util.List<Predicate<java.lang.String>>_packageFiltersprivate int_splitNumprivate int_splitPartitionprivate boolean_suiteHasBeenSetUpprivate boolean_testClassWrappersCreatedprivate TestEnvironment_testEnvironmentprivate java.util.TreeSet<TestSpec>_testSpecsprivate java.util.List<Predicate<IType>>_typeFiltersprivate java.util.List<java.lang.String>_withPackagesstatic java.lang.StringGOSU_SUITE_INCLUDE_TYPESstatic java.lang.StringSPLIT_PARTITION
-
Constructor Summary
Constructors Constructor Description Suite()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbeforeSuite()intcountTestCases()protected java.util.List<IDirectory>createDefaultGosuClassSearchPath()protected java.util.List<IDirectory>createDefaultJavaClassSearchPath()private TestEnvironmentdetermineTestEnvironmentBasedOnTestDefaults()private voidensureNoExplictlyAddedTests()TestEnvironmentgetTestEnvironment()private voidinitTypeSystem()booleanisLoggingErrors()TjavaAssertionsNotEnabled()Used to indicate that this suite does not require assertions be enabled.voidlogError(java.lang.String o)TlogErrors()private voidmaybeCreateTestClassWrappers()private voidmaybeInitSuite()private java.lang.IntegerreadIntegerSystemProperty(java.lang.String name)private voidrestrictTestSpecsToSpecifiedNames()This is for troubleshooting suite failures by running a subset of tests within a suite without requiring any Java or Gosu code changesprivate voidrestrictTestSpecsToSpecifiedPartition()org.junit.runner.Resultrun()Runs this Suite with a TextListener tied to System.out and returns the result.voidrun(junit.framework.TestResult result)private org.junit.runner.ResultrunImpl(junit.framework.Test test)booleanrunViaStaticSuiteMethod()A convenience method for running this suite from a main method.junit.framework.TesttestAt(int index)inttestCount()java.util.Enumeration<junit.framework.Test>tests()java.util.List<junit.framework.Test>testsAsList()java.util.List<junit.framework.TestSuite>testsAsListOfSuites()private TthisAsT()Private method that casts the this value as a T to avoid unchecked cast errors all over the placeprivate voidverifyNoFilters()TwithClasspathEntry(java.io.File srcDir)TwithIFileFilter(Predicate<IFile> fileFilter)Adds a file filter to this suite, allowing certain tests to be excluded.TwithModules(java.lang.String... moduleNames)This limits the gosu tests that are run to gosu tests that are located within the specified module in a gsrc or gtest directory AND all and java tests in the classpath that are not in a module.TwithPackageFilter(Predicate<java.lang.String> fileFilter)Adds a package filter to this suite, which allows you to exclude certain packages from consideration.TwithPackages(java.lang.String... packagePrefixes)Adds a package filter that will only accept packages that are subpackages of the strings passed in.TwithTest(IType type, java.lang.String... methods)Adds a test to this Suite.TwithTest(java.lang.Class type, java.lang.String... methods)Adds a test to this Suite.TwithTest(java.lang.String type, java.lang.String... methods)Adds a test to this Suite.TwithTestEnvironment(TestEnvironment testEnvironment)TwithTestTypeFilter(Predicate<IType> filter)Adds a type filter to this suite, allowing certain tests to be excluded.TwithTimeout(long seconds)
-
-
-
Field Detail
-
_testClassWrappersCreated
private boolean _testClassWrappersCreated
-
_suiteHasBeenSetUp
private boolean _suiteHasBeenSetUp
-
_packageFilters
private final java.util.List<Predicate<java.lang.String>> _packageFilters
-
_withPackages
private final java.util.List<java.lang.String> _withPackages
-
_testSpecs
private final java.util.TreeSet<TestSpec> _testSpecs
-
_gosuClassSearchPath
private final java.util.List<IDirectory> _gosuClassSearchPath
-
_javaClassSearchPath
private final java.util.List<IDirectory> _javaClassSearchPath
-
_modules
private final java.util.List<java.lang.String> _modules
-
_logErrorInfo
private boolean _logErrorInfo
-
_splitNum
private int _splitNum
-
_splitPartition
private int _splitPartition
-
_executionManager
private TestExecutionManager _executionManager
-
_testEnvironment
private TestEnvironment _testEnvironment
-
GOSU_SUITE_INCLUDE_TYPES
public static final java.lang.String GOSU_SUITE_INCLUDE_TYPES
- See Also:
- Constant Field Values
-
SPLIT_PARTITION
public static final java.lang.String SPLIT_PARTITION
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTestEnvironment
public TestEnvironment getTestEnvironment()
-
javaAssertionsNotEnabled
public final T javaAssertionsNotEnabled()
Used to indicate that this suite does not require assertions be enabled. In general it is recommended that you not use this option.
-
withTest
public final T withTest(IType type, java.lang.String... methods)
Adds a test to this Suite. This method is not to be combined with the module/filter methods.
-
withTest
public final T withTest(java.lang.String type, java.lang.String... methods)
Adds a test to this Suite. This method is not to be combined with the module/filter methods.
-
withTest
public final T withTest(java.lang.Class type, java.lang.String... methods)
Adds a test to this Suite. This method is not to be combined with the module/filter methods.
-
verifyNoFilters
private void verifyNoFilters()
-
withTestTypeFilter
public final T withTestTypeFilter(Predicate<IType> filter)
Adds a type filter to this suite, allowing certain tests to be excluded. Note that this is a significantly slower option thanwithIFileFilter(gw.util.Predicate)orwithPackageFilter(gw.util.Predicate)If possible, it is advisable to use a file filter instead.
-
withIFileFilter
public final T withIFileFilter(Predicate<IFile> fileFilter)
Adds a file filter to this suite, allowing certain tests to be excluded. Consider usingwithPackageFilter(gw.util.Predicate)if you wish to more easily apply a package filter of tests without dealing with ugly file paths. Package filters are just as fast as file filters, both of which are much faster than test type filters.
-
withPackages
public final T withPackages(java.lang.String... packagePrefixes)
Adds a package filter that will only accept packages that are subpackages of the strings passed in.
-
ensureNoExplictlyAddedTests
private void ensureNoExplictlyAddedTests()
-
withPackageFilter
public final T withPackageFilter(Predicate<java.lang.String> fileFilter)
Adds a package filter to this suite, which allows you to exclude certain packages from consideration. These filters are about as fast as file filters, but are easier to write and maintain. For the common case of simply wishing to test certain packages and their sub-packages, usewithPackages(String...)instead.
-
withTimeout
public final T withTimeout(long seconds)
-
withTestEnvironment
public T withTestEnvironment(TestEnvironment testEnvironment)
-
logErrors
public final T logErrors()
-
withModules
public final T withModules(java.lang.String... moduleNames)
This limits the gosu tests that are run to gosu tests that are located within the specified module in a gsrc or gtest directory AND all and java tests in the classpath that are not in a module.- Parameters:
moduleNames-- Returns:
-
withClasspathEntry
public T withClasspathEntry(java.io.File srcDir)
-
countTestCases
public final int countTestCases()
- Specified by:
countTestCasesin interfacejunit.framework.Test- Overrides:
countTestCasesin classjunit.framework.TestSuite
-
testAt
public final junit.framework.Test testAt(int index)
- Overrides:
testAtin classjunit.framework.TestSuite
-
testCount
public final int testCount()
- Overrides:
testCountin classjunit.framework.TestSuite
-
tests
public final java.util.Enumeration<junit.framework.Test> tests()
- Overrides:
testsin classjunit.framework.TestSuite
-
maybeCreateTestClassWrappers
private void maybeCreateTestClassWrappers()
-
determineTestEnvironmentBasedOnTestDefaults
private TestEnvironment determineTestEnvironmentBasedOnTestDefaults()
-
maybeInitSuite
private void maybeInitSuite()
-
createDefaultGosuClassSearchPath
protected java.util.List<IDirectory> createDefaultGosuClassSearchPath()
-
createDefaultJavaClassSearchPath
protected java.util.List<IDirectory> createDefaultJavaClassSearchPath()
-
initTypeSystem
private void initTypeSystem()
-
logError
public void logError(java.lang.String o)
-
run
public void run(junit.framework.TestResult result)
- Specified by:
runin interfacejunit.framework.Test- Overrides:
runin classjunit.framework.TestSuite
-
beforeSuite
protected void beforeSuite()
-
runViaStaticSuiteMethod
public final boolean runViaStaticSuiteMethod()
A convenience method for running this suite from a main method. Subclasses of Suite can create a main method like so:public static void main(String[] args) { System.exit( new GosuSuite().runSuite() ? 0 : 1 ); }- Returns:
- a boolean saying if all tests passed
-
runImpl
private org.junit.runner.Result runImpl(junit.framework.Test test)
-
run
public final org.junit.runner.Result run()
Runs this Suite with a TextListener tied to System.out and returns the result.
-
testsAsList
public java.util.List<junit.framework.Test> testsAsList()
-
testsAsListOfSuites
public java.util.List<junit.framework.TestSuite> testsAsListOfSuites()
-
isLoggingErrors
public boolean isLoggingErrors()
-
thisAsT
private T thisAsT()
Private method that casts the this value as a T to avoid unchecked cast errors all over the place- Returns:
- this
-
readIntegerSystemProperty
private java.lang.Integer readIntegerSystemProperty(java.lang.String name)
-
restrictTestSpecsToSpecifiedPartition
private void restrictTestSpecsToSpecifiedPartition()
-
restrictTestSpecsToSpecifiedNames
private void restrictTestSpecsToSpecifiedNames()
This is for troubleshooting suite failures by running a subset of tests within a suite without requiring any Java or Gosu code changes
-
-