Skip to content

Commit ada1b4b

Browse files
committed
#2432 add tests for remaining feature check
1 parent 523902f commit ada1b4b

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.intuit.karate.core.features;
2+
3+
import com.intuit.karate.Results;
4+
import com.intuit.karate.Runner;
5+
import com.intuit.karate.Suite;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class RemainingFeaturesTest {
11+
12+
private static Suite suite;
13+
14+
@Test
15+
void testRemainingFeaturesSingleThread() {
16+
verifyRemainingFeaturesWithThreads(1);
17+
}
18+
19+
@Test
20+
void testRemainingFeaturesParallel() {
21+
verifyRemainingFeaturesWithThreads(2);
22+
}
23+
24+
/**
25+
* Hooks into the current suite to return the remaining features within the test
26+
* @return Remaining features count
27+
*/
28+
public static long remainingFeatures() {
29+
return suite.getFeaturesRemaining();
30+
}
31+
32+
private void verifyRemainingFeaturesWithThreads(int threads) {
33+
Runner.Builder<?> builder = Runner.builder()
34+
.path("classpath:com/intuit/karate/core/features")
35+
.configDir("classpath:com/intuit/karate/core/features")
36+
.threads(threads);
37+
builder.resolveAll();
38+
suite = new Suite(builder);
39+
suite.run();
40+
Results results = suite.buildResults();
41+
assertEquals(0, results.getFailCount(), results.getErrorMessages());
42+
}
43+
44+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature:
2+
3+
Scenario: feature test 1
4+
* def numOfFeaturesLeft = remainingFeatures()
5+
* print 'Features left (including this one):', numOfFeaturesLeft
6+
# this is the first feature that runs, so there should be more than 1 feature running
7+
* assert numOfFeaturesLeft > 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature:
2+
3+
Scenario: feature test 2
4+
* def numOfFeaturesLeft = remainingFeatures()
5+
* print 'Features left (including this one):', numOfFeaturesLeft
6+
# there should always be at least 1 feature left, even if it's the current feature running
7+
* assert numOfFeaturesLeft >= 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function karateConfig() {
2+
const config = {}
3+
4+
const RemainingFeaturesTest = Java.type('com.intuit.karate.core.features.RemainingFeaturesTest')
5+
config.remainingFeatures = RemainingFeaturesTest.remainingFeatures
6+
7+
return config
8+
}

0 commit comments

Comments
 (0)