Skip to content

Commit

Permalink
#2432 add tests for remaining feature check
Browse files Browse the repository at this point in the history
  • Loading branch information
dvargas46 committed Feb 23, 2024
1 parent 523902f commit ada1b4b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.intuit.karate.core.features;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.Suite;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RemainingFeaturesTest {

private static Suite suite;

@Test
void testRemainingFeaturesSingleThread() {
verifyRemainingFeaturesWithThreads(1);
}

@Test
void testRemainingFeaturesParallel() {
verifyRemainingFeaturesWithThreads(2);
}

/**
* Hooks into the current suite to return the remaining features within the test
* @return Remaining features count
*/
public static long remainingFeatures() {
return suite.getFeaturesRemaining();
}

private void verifyRemainingFeaturesWithThreads(int threads) {
Runner.Builder<?> builder = Runner.builder()
.path("classpath:com/intuit/karate/core/features")
.configDir("classpath:com/intuit/karate/core/features")
.threads(threads);
builder.resolveAll();
suite = new Suite(builder);
suite.run();
Results results = suite.buildResults();
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature:

Scenario: feature test 1
* def numOfFeaturesLeft = remainingFeatures()
* print 'Features left (including this one):', numOfFeaturesLeft
# this is the first feature that runs, so there should be more than 1 feature running
* assert numOfFeaturesLeft > 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature:

Scenario: feature test 2
* def numOfFeaturesLeft = remainingFeatures()
* print 'Features left (including this one):', numOfFeaturesLeft
# there should always be at least 1 feature left, even if it's the current feature running
* assert numOfFeaturesLeft >= 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function karateConfig() {
const config = {}

const RemainingFeaturesTest = Java.type('com.intuit.karate.core.features.RemainingFeaturesTest')
config.remainingFeatures = RemainingFeaturesTest.remainingFeatures

return config
}

0 comments on commit ada1b4b

Please sign in to comment.