Skip to content

Commit

Permalink
fix: Cannot run normal JUnit 5 test methods with multiple parameters (#…
Browse files Browse the repository at this point in the history
…1535)

Signed-off-by: sheche <[email protected]>
  • Loading branch information
jdneo authored Feb 28, 2023
1 parent 52c9189 commit 9add95f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
let rawParamsString: string = rawName.substring(rawName.indexOf('(') + 1, rawName.indexOf(')'));
// We're going to replace any '$' characters with '.' characters to simplify the following logic.
// NOTE: you will get '$' characters in the name if you have a nested class.
rawParamsString = rawParamsString.replace(/\$/g, '.');
rawParamsString = rawParamsString.replace(/\$/g, '.')
.replace(/\\,/g, ',')
.replace(/ /g, '');

const params: string[] = rawParamsString.split(',');
let paramString: string = '';
Expand Down
33 changes: 32 additions & 1 deletion test/suite/JUnitAnalyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ org.opentest4j.AssertionFailedError: expected: <1> but was: <2>

const analyzer = new JUnitRunnerResultAnalyzer(runnerContext);

// We need to stub this method to avoid isssues with the TestController
// We need to stub this method to avoid issues with the TestController
// not being set up in the non-test version of the utils file.
const stub = sinon.stub(analyzer, "enlistDynamicMethodToTestMapping");
const dummy = generateTestItem(testController, '[__INVOCATION__]-dummy', TestKind.JUnit5, new Range(10, 0, 16, 0));
Expand All @@ -438,4 +438,35 @@ org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
sinon.assert.calledWith(passedSpy, dummy);
});

test("can handle normal test method with multiple arguments", () => {
const testItem = generateTestItem(testController, '[email protected]#test(Vertx,VertxTestContext)', TestKind.JUnit5, new Range(10, 0, 16, 0));
const testRunRequest = new TestRunRequest([testItem], []);
const testRun = testController.createTestRun(testRunRequest);
const startedSpy = sinon.spy(testRun, 'started');
const passedSpy = sinon.spy(testRun, 'passed');
const testRunnerOutput = `%TESTC 1 v2
%TSTTREE2,junit5.VertxTest,true,1,false,1,VertxTest,,[engine:junit-jupiter]/[class:junit5.VertxTest]
%TSTTREE3,test(junit5.VertxTest),false,1,false,2,test(Vertx\\, VertxTestContext),io.vertx.core.Vertx\\, io.vertx.junit5.VertxTestContext,[engine:junit-jupiter]/[class:junit5.VertxTest]/[method:test(io.vertx.core.Vertx\\, io.vertx.junit5.VertxTestContext)]
%TESTS 3,test(junit5.VertxTest)
%TESTE 3,test(junit5.VertxTest)
%RUNTIME1066`;
const runnerContext: IRunTestContext = {
isDebug: false,
kind: TestKind.JUnit5,
projectName: 'junit',
testItems: [testItem],
testRun: testRun,
workspaceFolder: workspace.workspaceFolders?.[0]!,
};

const analyzer = new JUnitRunnerResultAnalyzer(runnerContext);

analyzer.analyzeData(testRunnerOutput);

sinon.assert.calledWith(startedSpy, testItem);
sinon.assert.calledWith(passedSpy, testItem);
});

});
6 changes: 6 additions & 0 deletions test/test-projects/junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>4.3.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
18 changes: 18 additions & 0 deletions test/test-projects/junit/src/test/java/junit5/VertxTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package junit5;

import io.vertx.core.Vertx;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(VertxExtension.class)
public class VertxTest {

// test normal methods with multiple parameters
@Test
void test(Vertx vertx, VertxTestContext testContext) throws InterruptedException {
testContext.completeNow();
}

}

0 comments on commit 9add95f

Please sign in to comment.