Ignored JUnit Assert method calls made outside the main thread

Continuous planning of small tasks is the main concept of my application. Most of the methods are static and are presented in two forms: the public method executeSomeAction(Some param), which plans to carry out its private instance: ThreadPool.execute(() -> someAction()).

The thing is that most methods are cut into small tasks that can be performed simultaneously, and although they pass separate calls to ThreadPool functions, I prefer to keep these "smaller" methods static and private. Needless to say, it is not so easy to write a test that checks whether the static method has been executed, as it would be with the object. I am pleased with the performance and overall structure of the applications (with emphasis on immutable data and multi-threaded execution), but I have no idea how to write unit tests for some of these materials.

For example, I recently realized that even tests of the main methods ... always pass due to the execution of child threads, and not the main test one:

@Test
public void shouldExecutePassedRunnables() {
    final int expectedCounterValue = 1;
    final AtomicInteger counter = new AtomicInteger();
    ThreadPool.execute(() -> {
        counter.getAndIncrement();
        ThreadPool.execute(() -> Assert.assertEquals(Tests.shouldSucceed("Counter incrementation"),
                counter.get(), expectedCounterValue));
    });
    ThreadPool.awaitTermination(Tests.DEFAULT_DELAY);
}

, Assert.fail() , , . Assert .

. , , , . .

API, 100% ( -), , , ThreadPool PROPERLY . ? ( JUnit), ?

+4

All Articles