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.TestSuite
This 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 static String
GOSU_SUITE_INCLUDE_TYPES
static String
SPLIT_PARTITION
-
Constructor Summary
Constructors Constructor Description Suite()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
beforeSuite()
int
countTestCases()
protected List<IDirectory>
createDefaultGosuClassSearchPath()
protected List<IDirectory>
createDefaultJavaClassSearchPath()
TestEnvironment
getTestEnvironment()
boolean
isLoggingErrors()
T
javaAssertionsNotEnabled()
Used to indicate that this suite does not require assertions be enabled.void
logError(String o)
T
logErrors()
org.junit.runner.Result
run()
Runs this Suite with a TextListener tied to System.out and returns the result.void
run(junit.framework.TestResult result)
boolean
runViaStaticSuiteMethod()
A convenience method for running this suite from a main method.junit.framework.Test
testAt(int index)
int
testCount()
Enumeration<junit.framework.Test>
tests()
List<junit.framework.Test>
testsAsList()
List<junit.framework.TestSuite>
testsAsListOfSuites()
T
withClasspathEntry(File srcDir)
T
withIFileFilter(Predicate<IFile> fileFilter)
Adds a file filter to this suite, allowing certain tests to be excluded.T
withModules(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.T
withPackageFilter(Predicate<String> fileFilter)
Adds a package filter to this suite, which allows you to exclude certain packages from consideration.T
withPackages(String... packagePrefixes)
Adds a package filter that will only accept packages that are subpackages of the strings passed in.T
withTest(IType type, String... methods)
Adds a test to this Suite.T
withTest(Class type, String... methods)
Adds a test to this Suite.T
withTest(String type, String... methods)
Adds a test to this Suite.T
withTestEnvironment(TestEnvironment testEnvironment)
T
withTestTypeFilter(Predicate<IType> filter)
Adds a type filter to this suite, allowing certain tests to be excluded.T
withTimeout(long seconds)
-
-
-
Field Detail
-
GOSU_SUITE_INCLUDE_TYPES
public static final String GOSU_SUITE_INCLUDE_TYPES
- See Also:
- Constant Field Values
-
SPLIT_PARTITION
public static final 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, 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(String type, 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(Class type, String... methods)
Adds a test to this Suite. This method is not to be combined with the module/filter methods.
-
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(String... packagePrefixes)
Adds a package filter that will only accept packages that are subpackages of the strings passed in.
-
withPackageFilter
public final T withPackageFilter(Predicate<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(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:
-
countTestCases
public final int countTestCases()
- Specified by:
countTestCases
in interfacejunit.framework.Test
- Overrides:
countTestCases
in classjunit.framework.TestSuite
-
testAt
public final junit.framework.Test testAt(int index)
- Overrides:
testAt
in classjunit.framework.TestSuite
-
testCount
public final int testCount()
- Overrides:
testCount
in classjunit.framework.TestSuite
-
tests
public final Enumeration<junit.framework.Test> tests()
- Overrides:
tests
in classjunit.framework.TestSuite
-
createDefaultGosuClassSearchPath
protected List<IDirectory> createDefaultGosuClassSearchPath()
-
createDefaultJavaClassSearchPath
protected List<IDirectory> createDefaultJavaClassSearchPath()
-
logError
public void logError(String o)
-
run
public void run(junit.framework.TestResult result)
- Specified by:
run
in interfacejunit.framework.Test
- Overrides:
run
in 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
-
run
public final org.junit.runner.Result run()
Runs this Suite with a TextListener tied to System.out and returns the result.
-
testsAsList
public List<junit.framework.Test> testsAsList()
-
testsAsListOfSuites
public List<junit.framework.TestSuite> testsAsListOfSuites()
-
isLoggingErrors
public boolean isLoggingErrors()
-
-