Hi,
I am trying to assert on a different thread.
@Test
void assertInOtherThread() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
latch.countDown();
Assertions.assertTrue(false);
}).start();
latch.await();
}
Even though the test is failing, it’s reported as a success -
Exception in thread "Thread-3" org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:180)
at oxidant.core.streams.CollectorsTest.lambda$assertInOtherThread$1(CollectorsTest.java:74)
at java.base/java.lang.Thread.run(Thread.java:831)
BUILD SUCCESSFUL in 745ms
build.gradle test config -
tasks.named('test', Test) {
useJUnitPlatform()
}
Gradle version: 8.0
The build should fail as the assertion is failing. Appreciate your kind help.