Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1329 - JUnit 5 TestSource #1334

Merged
merged 2 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion karate-core/src/main/java/com/intuit/karate/core/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.intuit.karate.core;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -284,6 +286,16 @@ public void setExampleIndex(int exampleIndex) {
@Override
public String toString() {
return feature.toString() + getDisplayMeta();
}
}

// fetch src uri to point to scenario in feature file.
public URI getScenarioSrcUri() {
// this could be made conditional based on config - if navigating to feature file needed, then use below else return null.
String workingDir = System.getProperty("user.dir");
// we can use getPath as well - though that will point to feature file from compiled location i.e. target
String featurePath = this.feature.getRelativePath().replace("classpath:", "");
return URI.create(new File(workingDir + "/src/test/java/" + featurePath).toURI().toString() + "?line="
+ this.line);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import com.intuit.karate.core.HtmlFeatureReport;
import com.intuit.karate.core.HtmlSummaryReport;
import com.intuit.karate.core.ScenarioExecutionUnit;

import java.io.File;
import java.net.URI;
import java.util.Iterator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DynamicTest;
Expand Down Expand Up @@ -69,7 +72,7 @@ public boolean hasNext() {
@Override
public DynamicTest next() {
ScenarioExecutionUnit unit = iterator.next();
return DynamicTest.dynamicTest(unit.scenario.getNameForReport(), () -> {
return DynamicTest.dynamicTest(unit.scenario.getNameForReport(), unit.scenario.getScenarioSrcUri() ,() -> {
if (featureUnit.isSelected(unit)) {
unit.run();
}
Expand All @@ -93,5 +96,4 @@ public DynamicTest next() {
public Iterator<DynamicTest> iterator() {
return this;
}

}