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

feat: add Karate runner argument to ignore JUnit 5 no scenarios assertion #2532

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
10 changes: 9 additions & 1 deletion karate-core/src/main/java/com/intuit/karate/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
import com.intuit.karate.http.HttpClientFactory;
import com.intuit.karate.report.SuiteReports;
import com.intuit.karate.resource.ResourceUtils;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import org.slf4j.LoggerFactory;

/**
*
Expand Down Expand Up @@ -112,6 +113,7 @@ public static class Builder<T extends Builder> {
boolean outputCucumberJson;
boolean dryRun;
boolean debugMode;
boolean failWhenNoScenariosFound;
Map<String, String> systemProperties;
Map<String, Object> callSingleCache;
Map<String, ScenarioCall.Result> callOnceCache;
Expand Down Expand Up @@ -145,6 +147,7 @@ public synchronized Builder copy() {
b.outputCucumberJson = outputCucumberJson;
b.dryRun = dryRun;
b.debugMode = debugMode;
b.failWhenNoScenariosFound = failWhenNoScenariosFound;
b.systemProperties = systemProperties;
b.callSingleCache = callSingleCache;
b.callOnceCache = callOnceCache;
Expand Down Expand Up @@ -436,6 +439,11 @@ public T debugMode(boolean value) {
debugMode = value;
return (T) this;
}

public T failWhenNoScenariosFound(boolean value) {
failWhenNoScenariosFound = value;
return (T) this;
}

public T callSingleCache(Map<String, Object> value) {
callSingleCache = value;
Expand Down
19 changes: 8 additions & 11 deletions karate-core/src/main/java/com/intuit/karate/Suite.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,30 @@
import com.intuit.karate.core.FeatureCall;
import com.intuit.karate.core.FeatureResult;
import com.intuit.karate.core.FeatureRuntime;
import com.intuit.karate.driver.DriverRunner;
import com.intuit.karate.report.ReportUtils;
import com.intuit.karate.core.Scenario;
import com.intuit.karate.core.ScenarioCall;
import com.intuit.karate.core.ScenarioResult;
import com.intuit.karate.core.ScenarioRuntime;
import com.intuit.karate.core.Step;
import com.intuit.karate.core.SyncExecutorService;
import com.intuit.karate.core.Tags;
import com.intuit.karate.driver.DriverRunner;
import com.intuit.karate.http.HttpClientFactory;
import com.intuit.karate.report.ReportUtils;
import com.intuit.karate.report.SuiteReports;
import com.intuit.karate.resource.Resource;
import com.intuit.karate.resource.ResourceUtils;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.LoggerFactory;

import static java.util.function.Predicate.not;

Expand All @@ -78,6 +72,7 @@ public class Suite implements Runnable {
public final String tagSelector;
public final boolean dryRun;
public final boolean debugMode;
public final boolean failWhenNoScenariosFound;
public final File workingDir;
public final String buildDir;
public final String reportDir;
Expand Down Expand Up @@ -135,6 +130,7 @@ public Suite(Runner.Builder rb) {
if (rb.forTempUse) {
dryRun = false;
debugMode = false;
failWhenNoScenariosFound = false;
backupReportDir = false;
outputHtmlReport = false;
outputCucumberJson = false;
Expand Down Expand Up @@ -179,6 +175,7 @@ public Suite(Runner.Builder rb) {
outputJunitXml = rb.outputJunitXml;
dryRun = rb.dryRun;
debugMode = rb.debugMode;
failWhenNoScenariosFound = rb.failWhenNoScenariosFound;
classLoader = rb.classLoader;
clientFactory = rb.clientFactory;
env = rb.env;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.intuit.karate.Runner;
import com.intuit.karate.Suite;
import com.intuit.karate.core.Feature;
import com.intuit.karate.core.FeatureCall;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DynamicContainer;
Expand Down Expand Up @@ -68,7 +67,7 @@ public Iterator<DynamicNode> iterator() {
DynamicNode node = DynamicContainer.dynamicContainer(testName, featureNode);
list.add(node);
}
if (list.isEmpty()) {
if (suite.failWhenNoScenariosFound && list.isEmpty()) {
Assertions.fail("no features or scenarios found: " + this);
}
return list.iterator();
Expand Down
22 changes: 22 additions & 0 deletions karate-junit5/src/test/java/karate/NoFeatureNoScenarioTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package karate;

import com.intuit.karate.junit5.Karate;

class NoFeatureNoScenarioTest {

@Karate.Test
Karate testHasScenariosWithFailWhenNoScenariosFound() {
return Karate.run("noFeatureNoScenario")
.tags("@smoke")
.failWhenNoScenariosFound(true)
.relativeTo(getClass());
}

@Karate.Test
Karate testNoScenarios() {
return Karate.run("noFeatureNoScenario")
.tags("@tagnotexist")
.failWhenNoScenariosFound(false)
.relativeTo(getClass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: ignoreJunitNoScenariosAssertion argument for Karate runner

@smoke
Scenario: smoke
* print 'smoke'