Skip to content

Support @MockBean on test fields with TestNG #7689

@qerub

Description

@qerub

Using @MockBean on test fields is a very succinct way to mock components.

At the moment, it only works with JUnit tests via SpringRunner.

It would be great if it also worked with TestNG via AbstractTestNGSpringContextTests.

Example

@SpringBootTest
public class TestNGMockBeanTest extends AbstractTestNGSpringContextTests {

    @MockBean
    DemoComponent demoComponent;

    @Test
    public void mockBeanShouldWork() {
        assertTrue(demoComponent != null, "demoComponent is null");
        assertTrue(new MockUtil().isMock(demoComponent), "demoComponent is not a mock");
    }

}

Desired behaviour: Test passes.

Current behaviour: "demoComponent is null" assertion triggers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions