Class GlobalThreadMonitorExtension

java.lang.Object
fr.ght1pc9kc.testy.core.extensions.GlobalThreadMonitorExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.Extension

public class GlobalThreadMonitorExtension extends Object implements org.junit.jupiter.api.extension.AfterAllCallback
Print all non-daemon threads after the test execution.

Example of use as a class extension:


 @ExtendWith(GlobalThreadMonitorExtension.class)
 class NestedExtensionTest {
     @Test
     void should_complete_test_with_non_daemon_thread_running() {
         executors.submit(() -> {
             try {
                 Thread.sleep(5000);
             } catch (InterruptedException e) {
                 // ignore
             }
         });

         Assertions.assertThat(executors.isShutdown()).isFalse();
     }
 }
 

To use it as a global extension to detect a problem, add -Djunit.jupiter.extensions.autodetection.enabled=true to the test launch options

  • Constructor Details

    • GlobalThreadMonitorExtension

      public GlobalThreadMonitorExtension()
  • Method Details

    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback