Package randoop.output
Class JUnitCreator
java.lang.Object
randoop.output.JUnitCreator
Creates Java source as
String
for a suite of JUnit4 tests.-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
The JUnit annotation for the AfterAll option.private static final String
The method name for the AfterAll option.private static final String
The JUnit annotation for the AfterEach option.private static final String
The method name for the AfterEach option.private com.github.javaparser.ast.stmt.BlockStmt
The Java text for AfterAll method of generated test class.private com.github.javaparser.ast.stmt.BlockStmt
The Java text for AfterEach method of generated test class.private static final String
The JUnit annotation for the BeforeAll option.private static final String
The method name for the BeforeAll option.private static final String
The JUnit annotation for the BeforeEach option.private static final String
The method name for the BeforeEach option.private com.github.javaparser.ast.stmt.BlockStmt
The Java text for BeforeAll method of generated test class.private com.github.javaparser.ast.stmt.BlockStmt
The Java text for BeforeEach method of generated test class.classMethodCounts maps test class names to the number of methods in each class.(package private) static com.github.javaparser.JavaParser
An instance of a Java parser.private final String
The package name.private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier>
The "public" modifier.private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier>
The "public" and "static" modifiers. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAfterAll
(com.github.javaparser.ast.stmt.BlockStmt body) Add text for AfterClass-annotated method in each generated text class.private void
addAfterEach
(com.github.javaparser.ast.stmt.BlockStmt text) Add text for After-annotated method in each generated test class.private void
addBeforeAll
(com.github.javaparser.ast.stmt.BlockStmt body) Add text for BeforeClass-annotated method in each generated test class.private void
addBeforeEach
(com.github.javaparser.ast.stmt.BlockStmt body) Add text for Before-annotated method in each generated test class.private com.github.javaparser.ast.body.MethodDeclaration
createFixture
(String annotation, com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers, String methodName, com.github.javaparser.ast.stmt.BlockStmt body) Creates the declaration of a single test fixture.com.github.javaparser.ast.CompilationUnit
createTestClass
(String testClassName, NameGenerator methodNameGen, List<ExecutableSequence> sequences) Create a test class.createTestDriver
(String driverName, Iterable<String> testClassNames, int numMethods) Create non-reflective test driver as a main class.private com.github.javaparser.ast.body.MethodDeclaration
createTestMethod
(String className, String methodName, ExecutableSequence testSequence) Creates a test method as aString
for the sequencetestSequence
.createTestSuite
(String suiteClassName, Iterable<String> testClassNames) Creates the JUnit4 suite class for the tests in this object as aString
.static JUnitCreator
getTestCreator
(String junit_package_name, com.github.javaparser.ast.stmt.BlockStmt beforeAllBody, com.github.javaparser.ast.stmt.BlockStmt afterAllBody, com.github.javaparser.ast.stmt.BlockStmt beforeEachBody, com.github.javaparser.ast.stmt.BlockStmt afterEachBody) static com.github.javaparser.ast.stmt.BlockStmt
parseFixture
(List<String> bodyText)
-
Field Details
-
javaParser
static com.github.javaparser.JavaParser javaParserAn instance of a Java parser. -
PUBLIC
private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLICThe "public" modifier. -
PUBLIC_STATIC
private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLIC_STATICThe "public" and "static" modifiers. -
packageName
The package name. May be null, but may not be the empty string. -
classMethodCounts
classMethodCounts maps test class names to the number of methods in each class. This is used to generate lists of method names for a class. Each test method is named TEST_METHOD_NAME_PREFIX+i for some integer i. -
beforeAllBody
private com.github.javaparser.ast.stmt.BlockStmt beforeAllBodyThe Java text for BeforeAll method of generated test class. -
afterAllBody
private com.github.javaparser.ast.stmt.BlockStmt afterAllBodyThe Java text for AfterAll method of generated test class. -
beforeEachBody
private com.github.javaparser.ast.stmt.BlockStmt beforeEachBodyThe Java text for BeforeEach method of generated test class. -
afterEachBody
private com.github.javaparser.ast.stmt.BlockStmt afterEachBodyThe Java text for AfterEach method of generated test class. -
BEFORE_ALL
The JUnit annotation for the BeforeAll option.- See Also:
-
AFTER_ALL
The JUnit annotation for the AfterAll option.- See Also:
-
BEFORE_EACH
The JUnit annotation for the BeforeEach option.- See Also:
-
AFTER_EACH
The JUnit annotation for the AfterEach option.- See Also:
-
BEFORE_ALL_METHOD
The method name for the BeforeAll option.- See Also:
-
AFTER_ALL_METHOD
The method name for the AfterAll option.- See Also:
-
BEFORE_EACH_METHOD
The method name for the BeforeEach option.- See Also:
-
AFTER_EACH_METHOD
The method name for the AfterEach option.- See Also:
-
-
Constructor Details
-
JUnitCreator
-
-
Method Details
-
getTestCreator
public static JUnitCreator getTestCreator(String junit_package_name, com.github.javaparser.ast.stmt.BlockStmt beforeAllBody, com.github.javaparser.ast.stmt.BlockStmt afterAllBody, com.github.javaparser.ast.stmt.BlockStmt beforeEachBody, com.github.javaparser.ast.stmt.BlockStmt afterEachBody) -
addBeforeAll
private void addBeforeAll(com.github.javaparser.ast.stmt.BlockStmt body) Add text for BeforeClass-annotated method in each generated test class.- Parameters:
body
- the (Java) text for method
-
addAfterAll
private void addAfterAll(com.github.javaparser.ast.stmt.BlockStmt body) Add text for AfterClass-annotated method in each generated text class.- Parameters:
body
- the (Java) text for method
-
addBeforeEach
private void addBeforeEach(com.github.javaparser.ast.stmt.BlockStmt body) Add text for Before-annotated method in each generated test class.- Parameters:
body
- the (Java) text for method
-
addAfterEach
private void addAfterEach(com.github.javaparser.ast.stmt.BlockStmt text) Add text for After-annotated method in each generated test class.- Parameters:
text
- the (Java) text for method
-
createTestClass
public com.github.javaparser.ast.CompilationUnit createTestClass(String testClassName, NameGenerator methodNameGen, List<ExecutableSequence> sequences) Create a test class.- Parameters:
testClassName
- the class namemethodNameGen
- the generator that creates method namessequences
- the contents of the test methods- Returns:
- the CompilationUnit for a test class
-
createTestMethod
private com.github.javaparser.ast.body.MethodDeclaration createTestMethod(String className, String methodName, ExecutableSequence testSequence) Creates a test method as aString
for the sequencetestSequence
.- Parameters:
className
- the name of the test classmethodName
- the name of the test methodtestSequence
- theExecutableSequence
test sequence- Returns:
- the
String
for the test method
-
createFixture
private com.github.javaparser.ast.body.MethodDeclaration createFixture(String annotation, com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers, String methodName, com.github.javaparser.ast.stmt.BlockStmt body) Creates the declaration of a single test fixture.- Parameters:
annotation
- the fixture annotationmodifiers
- the method modifiers for fixture declarationmethodName
- the name of the fixture methodbody
- theBlockStmt
for the fixture- Returns:
- the fixture method as a
String
-
createTestSuite
Creates the JUnit4 suite class for the tests in this object as aString
.- Parameters:
suiteClassName
- the name of the suite class createdtestClassNames
- the names of the test classes in the suite- Returns:
- the
String
with the declaration for the suite class
-
createTestDriver
Create non-reflective test driver as a main class.- Parameters:
driverName
- the name for the driver classtestClassNames
- the names of the test classes in the suitenumMethods
- the number of methods; used for zero-padding- Returns:
- the test driver class as a
String
-
parseFixture
public static com.github.javaparser.ast.stmt.BlockStmt parseFixture(List<String> bodyText) throws com.github.javaparser.ParseException - Throws:
com.github.javaparser.ParseException
-