Skip to content

Commit

Permalink
feat: support test case selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Feb 6, 2025
1 parent b8e3769 commit 6daa84e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contrib/testng/src/mill/testng/TestNGRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import sbt.testing.Runner;
import sbt.testing.Task;
import sbt.testing.TaskDef;
import sbt.testing.TestSelector;
import sbt.testing.SuiteSelector;
import sbt.testing.Selector;
import java.util.ArrayList;
import java.util.List;

class TestNGTask implements Task {

Expand Down Expand Up @@ -55,11 +60,24 @@ public Task[] tasks(TaskDef[] taskDefs) {
CommandLineArgs cliArgs = new CommandLineArgs();
new JCommander(cliArgs).parse(args); // args is an output parameter of the constructor!
cliArgs.testClass = taskDefs[i].fullyQualifiedName();
cliArgs.commandLineMethods = testMethods(taskDefs[i].selectors(), taskDefs[i].fullyQualifiedName());
returnTasks[i] = new TestNGTask(taskDefs[i], testClassLoader, cliArgs);
}
return returnTasks;
}

private List<String> testMethods(Selector[] selectors, String testClass) {
ArrayList<String> testMethods = new ArrayList<String>();
for (int i = 0; i < selectors.length; i += 1) {
if(selectors[i] instanceof TestSelector) {
testMethods.add(testClass + "." + ((TestSelector) selectors[i]).testName());
} else if(selectors[i] instanceof SuiteSelector) {
return new ArrayList<String>();
}
}
return testMethods;
}

public String done() {
return null;
}
Expand Down

0 comments on commit 6daa84e

Please sign in to comment.