Skip to content

Commit afb197f

Browse files
committed
[integration-test] Add "fail fast" option
1 parent 2ddbf73 commit afb197f

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java

+20
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public enum DnsResolver {
128128

129129
public final ConnectionConfigurationBuilderApplier configurationApplier;
130130

131+
public final boolean failFast;
132+
131133
public final boolean verbose;
132134

133135
public final DnsResolver dnsResolver;
@@ -209,6 +211,7 @@ else if (StringUtils.isNotEmpty(builder.accountOneUsername, builder.accountOnePa
209211
}
210212
};
211213

214+
this.failFast = builder.failFast;
212215
this.verbose = builder.verbose;
213216

214217
this.dnsResolver = builder.dnsResolver;
@@ -270,6 +273,8 @@ public static final class Builder {
270273

271274
private Set<String> testPackages;
272275

276+
private boolean failFast;
277+
273278
private boolean verbose;
274279

275280
private DnsResolver dnsResolver = DnsResolver.minidns;
@@ -478,6 +483,20 @@ public Builder addTestPackages(String[] testPackagesString) {
478483
return this;
479484
}
480485

486+
public Builder setFailFast(boolean failFast) {
487+
this.failFast = failFast;
488+
return this;
489+
}
490+
491+
public Builder setFailFast(String failFastBooleanString) {
492+
if (failFastBooleanString == null) {
493+
return this;
494+
}
495+
496+
boolean failFast = ParserUtils.parseXmlBoolean(failFastBooleanString);
497+
return setFailFast(failFast);
498+
}
499+
481500
public Builder setVerbose(boolean verbose) {
482501
this.verbose = verbose;
483502
return this;
@@ -601,6 +620,7 @@ public static Configuration newConfiguration(String[] testPackages)
601620
builder.addTestPackages(properties.getProperty("testPackages"));
602621
builder.addTestPackages(testPackages);
603622

623+
builder.setFailFast(properties.getProperty("failFast"));
604624
builder.setVerbose(properties.getProperty("verbose"));
605625

606626
builder.setDnsResolver(properties.getProperty("dnsResolver"));

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,20 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
551551
LOGGER.info(sb.toString());
552552

553553
for (PreparedTest test : tests) {
554-
test.run();
554+
boolean successful = test.run();
555+
// Will only be not successful if a test failed and config.failFast is enabled.
556+
if (!successful) {
557+
break;
558+
}
555559
}
556560

557-
// Assert that all tests in the 'tests' list produced a result.
558-
assert numberOfAvailableTests == testRunResult.getNumberOfAvailableTests();
561+
if (!config.failFast) {
562+
// Assert that all tests in the 'tests' list produced a result.
563+
assert numberOfAvailableTests == testRunResult.getNumberOfAvailableTests();
564+
}
559565
}
560566

561-
private void runConcreteTest(ConcreteTest concreteTest)
567+
private boolean runConcreteTest(ConcreteTest concreteTest)
562568
throws InterruptedException, XMPPException, IOException, SmackException {
563569
LOGGER.info(concreteTest + " Start");
564570
var testStart = ZonedDateTime.now();
@@ -576,7 +582,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
576582
LOGGER.info(concreteTest + " is not possible");
577583
testRunResult.impossibleIntegrationTests.add(new TestNotPossible(concreteTest, testStart, testEnd,
578584
null, (TestNotPossibleException) cause));
579-
return;
585+
return true;
580586
}
581587
Throwable nonFatalFailureReason;
582588
// junit asserts throw an AssertionError if they fail, those should not be
@@ -593,7 +599,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
593599
sinttestDebugger.onTestFailure(concreteTest, testEnd, nonFatalFailureReason);
594600
}
595601
LOGGER.log(Level.SEVERE, concreteTest + " Failed", e);
596-
return;
602+
return false;
597603
}
598604
catch (IllegalArgumentException | IllegalAccessException e) {
599605
throw new AssertionError(e);
@@ -605,6 +611,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
605611
}
606612
LOGGER.info(concreteTest + " Success");
607613
testRunResult.successfulIntegrationTests.add(new SuccessfulTest(concreteTest, testStart, testEnd, null));
614+
return true;
608615
}
609616

610617
private static void verifyLowLevelTestMethod(Method method,
@@ -769,23 +776,29 @@ private PreparedTest(AbstractSmackIntTest test, List<ConcreteTest> concreteTests
769776
afterClassMethod = getSinttestSpecialMethod(testClass, AfterClass.class);
770777
}
771778

772-
public void run() throws InterruptedException, XMPPException, IOException, SmackException {
779+
public boolean run() throws InterruptedException, XMPPException, IOException, SmackException {
773780
try {
774781
// Run the @BeforeClass methods (if any)
775782
executeSinttestSpecialMethod(beforeClassMethod);
776783

777784
for (ConcreteTest concreteTest : concreteTests) {
778785
TEST_UNDER_EXECUTION = concreteTest;
786+
boolean successful;
779787
try {
780-
runConcreteTest(concreteTest);
788+
successful = runConcreteTest(concreteTest);
781789
} finally {
782790
TEST_UNDER_EXECUTION = null;
783791
}
792+
793+
if (config.failFast && !successful) {
794+
return false;
795+
}
784796
}
785797
}
786798
finally {
787799
executeSinttestSpecialMethod(afterClassMethod);
788800
}
801+
return true;
789802
}
790803

791804
private void executeSinttestSpecialMethod(Method method) {

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@
164164
* <td>List of packages with tests</td>
165165
* </tr>
166166
* <tr>
167+
* <td>failFast</td>
168+
* <td>If <code>true</code> exit immediatly on the first failure.</td>
169+
* </tr>
170+
* <tr>
167171
* <td>verbose</td>
168172
* <td>If <code>true</code> set output to verbose</td>
169173
* </tr>

0 commit comments

Comments
 (0)