Skip to content

Commit

Permalink
feat: can now specific a specific pom file to execute the test (#63)
Browse files Browse the repository at this point in the history
feat: can now specificy a pom file to execute the test
  • Loading branch information
danglotb authored Feb 18, 2019
1 parent 9f1a085 commit 4ba0fa1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
49 changes: 45 additions & 4 deletions src/main/java/eu/stamp_project/testrunner/maven/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,35 @@ public class EntryPoint {
*/
public static TestResult runTestClasses(String absolutePathToRootProject,
String... fullQualifiedNameOfTestClasses) {
return runTestClassesSpecificPom(absolutePathToRootProject, POM_FILE, fullQualifiedNameOfTestClasses);
}

/**
* Execution of various test classes.
* <p>
* Run all the test classes given as a full qualified name. For instance, my.package.MyClassTest.
* This methods will run all the test methods within the given test classes.
* </p>
*
* @param absolutePathToRootProject path to the root of the targeted project
* @param fullQualifiedNameOfTestClasses test classes to be run.
* @param pomFileName the filename of the pom to be used
* @return an instance of TestResult {@link TestResult} containing result of the exeuction of test methods.
*/
public static TestResult runTestClassesSpecificPom(String absolutePathToRootProject,
String pomFileName,
String... fullQualifiedNameOfTestClasses) {
if (fullQualifiedNameOfTestClasses.length > 0) {
EntryPoint.runMavenGoal(absolutePathToRootProject, GOAL_TEST, GOAL_SPECIFY +
String.join(TEST_CLASS_SEPARATOR, fullQualifiedNameOfTestClasses)
);
} else {
EntryPoint.runMavenGoal(absolutePathToRootProject, GOAL_TEST);
EntryPoint.runMavenGoal(absolutePathToRootProject, pomFileName, GOAL_TEST);
}
return new SurefireReportsReader().readAll(absolutePathToRootProject + "/" + PATH_TO_SUREFIRE);
}


/**
* Execution of various test methods inside a given test class.
* <p>
Expand All @@ -63,22 +82,44 @@ public static TestResult runTestClasses(String absolutePathToRootProject,
public static TestResult runTests(String absolutePathToRootProject,
String fullQualifiedNameOfTestClass,
String... testMethods) {
return runTestsSpecificPom(absolutePathToRootProject, fullQualifiedNameOfTestClass, POM_FILE, testMethods);
}

/**
* Execution of various test methods inside a given test class.
* <p>
* Run all the test methods given inside the given test class. The test class must be given as a full qualified name.
* For instance, my.package.MyClassTest.
* This methods will run all the test methods given.
* </p>
*
* @param absolutePathToRootProject path to the root of the targeted project
* @param fullQualifiedNameOfTestClass test class to be run.
* @param pomFileName the filename of the pom to be used
* @param testMethods test methods to be run.
* @return an instance of TestResult {@link TestResult} containing result of the execution of test methods.
*/
public static TestResult runTestsSpecificPom(String absolutePathToRootProject,
String fullQualifiedNameOfTestClass,
String pomFileName,
String... testMethods) {
if (testMethods.length > 0) {
EntryPoint.runMavenGoal(absolutePathToRootProject, GOAL_TEST, GOAL_SPECIFY +
EntryPoint.runMavenGoal(absolutePathToRootProject + "/" + pomFileName, GOAL_TEST, GOAL_SPECIFY +
fullQualifiedNameOfTestClass + TEST_CLASS_METHOD_SEPARATOR +
String.join(TEST_METHOD_SEPARATOR, testMethods)
);
} else {
EntryPoint.runMavenGoal(absolutePathToRootProject, GOAL_TEST);
EntryPoint.runMavenGoal(absolutePathToRootProject + "/" + pomFileName, GOAL_TEST);
}
return new SurefireReportsReader().readAll(absolutePathToRootProject + "/" + PATH_TO_SUREFIRE);
}


static int runMavenGoal(String absolutePathToPomFile, String... goals) {
LOGGER.info("run mvn {}", String.join(ConstantsHelper.WHITE_SPACE, goals));
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(Arrays.asList(goals));
request.setPomFile(new File(absolutePathToPomFile + "/" + POM_FILE));
request.setPomFile(new File(absolutePathToPomFile));
request.setJavaHome(new File(System.getProperty("java.home")));
request.setProperties(properties);
Invoker invoker = new DefaultInvoker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public TestResult read(String pathToSurefireReports) {
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
final NodeList testCases = doc.getElementsByTagName("testcase");
IntStream.range(0, testCases.getLength()).boxed()
.map(testCases::item)
Expand Down

0 comments on commit 4ba0fa1

Please sign in to comment.