Skip to content

Commit

Permalink
Feat: pre goals for maven execution (#64)
Browse files Browse the repository at this point in the history
* feat: can now pass preGoals

* test: add some pre goals to the test
  • Loading branch information
danglotb authored Feb 18, 2019
1 parent 4ba0fa1 commit 8c7747b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/main/java/eu/stamp_project/testrunner/maven/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class EntryPoint {

private static final Logger LOGGER = LoggerFactory.getLogger(EntryPoint.class);

public static String preGoals = "";

/**
* Execution of various test classes.
* <p>
Expand Down Expand Up @@ -53,8 +55,8 @@ public static TestResult runTestClasses(String absolutePathToRootProject,
* @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) {
String pomFileName,
String... fullQualifiedNameOfTestClasses) {
if (fullQualifiedNameOfTestClasses.length > 0) {
EntryPoint.runMavenGoal(absolutePathToRootProject, GOAL_TEST, GOAL_SPECIFY +
String.join(TEST_CLASS_SEPARATOR, fullQualifiedNameOfTestClasses)
Expand Down Expand Up @@ -100,9 +102,9 @@ public static TestResult runTests(String absolutePathToRootProject,
* @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) {
String fullQualifiedNameOfTestClass,
String pomFileName,
String... testMethods) {
if (testMethods.length > 0) {
EntryPoint.runMavenGoal(absolutePathToRootProject + "/" + pomFileName, GOAL_TEST, GOAL_SPECIFY +
fullQualifiedNameOfTestClass + TEST_CLASS_METHOD_SEPARATOR +
Expand All @@ -116,7 +118,14 @@ public static TestResult runTestsSpecificPom(String absolutePathToRootProject,


static int runMavenGoal(String absolutePathToPomFile, String... goals) {
LOGGER.info("run mvn {}", String.join(ConstantsHelper.WHITE_SPACE, goals));
final String[] splittedPreGoals = preGoals.isEmpty() ? new String[0] : preGoals.split(",");
if (!eu.stamp_project.testrunner.EntryPoint.persistence) {
preGoals = "";
}
final String[] finalGoals = new String[splittedPreGoals.length + goals.length];
System.arraycopy(splittedPreGoals, 0, finalGoals, 0, splittedPreGoals.length);
System.arraycopy(goals, 0, finalGoals, splittedPreGoals.length, goals.length);
LOGGER.info("run mvn {}", String.join(ConstantsHelper.WHITE_SPACE, finalGoals));
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(Arrays.asList(goals));
request.setPomFile(new File(absolutePathToPomFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ public void testOnSpecificTestMethod() {
When running with maven, assumption failure are consider as ignored.
*/

final TestResult testResult = EntryPoint.runTests("src/test/resources/test-projects",
"example.TestSuiteExample", "test2");
EntryPoint.preGoals = "--quiet,-Dverbose";

final TestResult testResult = EntryPoint.runTests(
"src/test/resources/test-projects",
"example.TestSuiteExample",
"test2"
);
assertEquals(1, testResult.getRunningTests().size());
assertEquals(1, testResult.getPassingTests().size());
assertEquals(0, testResult.getFailingTests().size());
Expand Down

0 comments on commit 8c7747b

Please sign in to comment.