更新时间:2022-12-19 07:41:41
Strangely, using the default cucumber's java runner doesn't allow Visual Studio Code nor Eclipse remote debugger to set a breakpoint on step definition.
But it's possible to solve this issue by using cucumber's junit4 runner. Here is an updated gradle configuration (notice, you don't need the "cucumber" task anymore):
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.guava:guava:27.1-jre'
// used for running cucumber steps + powermock
testCompile 'junit:junit:4.12'
testCompile 'io.cucumber:cucumber-java:4.3.0'
testCompile 'io.cucumber:cucumber-junit:4.3.0'
}
Note that junit:junit
dependency also contains a junit runner.
Then you can create an empty class, e.g.: JUnitRunnerWrapper
that will contain cucumber's configuration (via annotations):
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = { "pretty", "html:build/reports/tests/cucumber-html-report" },
glue = { "gradle.cucumber" },
features = "src/test/resources",
monochrome = true)
public class JUnitRunnerWrapper {
}
In order to make it work you have to install Java Test Runner
for vscode. Then you'll be able to see the "Run Test/Debug Test" under the JUnitRunnerWrapper
:
After pressing "Debug Test", vscode will launch the tests and breakpoints will be triggered:
Additional notes:
gradle test
commandRun Test
command can be shown using vscode Java: Show Test Output
command