Skip to content

@MicronautTest(rebuildContext = true) creates a context that is unable to be cleaned up #1218

@BrentDouglasB1

Description

@BrentDouglasB1

Expected Behavior

I would expect one context should be created per test case when rebuildContext is true, so that I should have at least one chance to access that context from an @AfterEach method.

Actual Behaviour

When beans are set to eager init they get created multiple times per test case. I have some suspicion that this is somehow related to why the DBUnit extension no longer works in M4 when rebuildContext is set to true but haven't had time to investigate yet.

Steps To Reproduce

@MicronautTest(rebuildContext = true)
public class RebuildContextTest {

    @Inject
    TestBean bean;

    @Test
    public void test() {
        assertEquals(1, TestBean.counter); // Is 2
    }
}

@Context
class TestBean {
    static int counter = 0;

    public TestBean() {
        counter++;
    }
}

Environment Information

  • OSX
  • 17

Example Application

No response

Version

4.7.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions