Skip to content

TestInstancePreDestroyCallback does not follow the wrapping behavior of callbacks in lifecycle PER_CLASS #2209

@joerg1985

Description

@joerg1985

The extension TestInstancePreDestroyCallback does not follow the wrapping behavior of Extensions if the lifecycle is PER_CLASS, as described in https://junit.org/junit5/docs/snapshot/user-guide/#extensions-execution-order-wrapping-behavior

The expected order with lifecycle PER_CLASS

  • Extension1.postProcessTestInstance
  • Extension2.postProcessTestInstance
  • Extension1.beforeAll
  • Extension2.beforeAll
  • Extension2.afterAll
  • Extension1.afterAll
  • Extension2.preDestroyTestInstance
  • Extension1.preDestroyTestInstance

The order using JUnit 5.6.0. with lifecycle PER_CLASS

  • Extension1.postProcessTestInstance
  • Extension2.postProcessTestInstance
  • Extension1.beforeAll
  • Extension2.beforeAll
  • Extension2.afterAll
  • Extension1.afterAll
  • Extension1.preDestroyTestInstance
  • Extension2.preDestroyTestInstance

The order using JUnit 5.6.0. with lifecycle PER_METHOD is as expected

  • Extension1.beforeAll
  • Extension2.beforeAll
  • Extension1.postProcessTestInstance
  • Extension2.postProcessTestInstance
  • Extension2.preDestroyTestInstance
  • Extension1.preDestroyTestInstance
  • Extension2.afterAll
  • Extension1.afterAll

Steps to reproduce

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith({ Dummy2Test.Extension1.class, Dummy2Test.Extension2.class })
public class Dummy2Test {
    private static final Logger LOG = Logger.getLogger(Dummy2Test.class.getName());
    
    @Test
    public void justATest() {
        LOG.fine("@Test");
    }
    
    public static class Extension1 implements BeforeAllCallback, AfterAllCallback , TestInstancePostProcessor,TestInstancePreDestroyCallback {

        @Override
        public void beforeAll(ExtensionContext ec) throws Exception {
            LOG.warning("Extension1.beforeAll");
        }

        @Override
        public void afterAll(ExtensionContext ec) throws Exception {
            LOG.warning("Extension1.afterAll");
        }
        
        @Override
        public void postProcessTestInstance(Object o, ExtensionContext ec) throws Exception {
            LOG.warning("Extension1.postProcessTestInstance");
        }

        @Override
        public void preDestroyTestInstance(ExtensionContext ec) throws Exception {
            LOG.warning("Extension1.preDestroyTestInstance");
        }
        
    }
    
    public static class Extension2 implements BeforeAllCallback, AfterAllCallback , TestInstancePostProcessor, TestInstancePreDestroyCallback {

        @Override
        public void beforeAll(ExtensionContext ec) throws Exception {
            LOG.warning("Extension2.beforeAll");
        }

        @Override
        public void afterAll(ExtensionContext ec) throws Exception {
            LOG.warning("Extension2.afterAll");
        }
        
        @Override
        public void postProcessTestInstance(Object o, ExtensionContext ec) throws Exception {
            LOG.warning("Extension2.postProcessTestInstance");
        }

        @Override
        public void preDestroyTestInstance(ExtensionContext ec) throws Exception {
            LOG.warning("Extension2.preDestroyTestInstance");
        }
    }
}

Context

  • Used versions (Jupiter/Vintage/Platform): 5.6.0
  • Build Tool/IDE: maven

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions