Skip to content

@MockBean not Working with SpringBootTest and Junit5Β #2654

Description

@sashokbg

πŸ‘“ What did you see?

When running a SpringBootTest with JUnit5 (Jupiter) all @MockBean annotations are not populated.

βœ… What did you expect to see?

Running the same test without cucumber configuration works with no issue.

πŸ“¦ Which tool/library version are you using?

Java - JDK 17
SpringBoot 2.7
Junit Jupiter - 5.8.2
cucumber-java - 7.8.1
cucumber-spring - 7.8.1
cucumber-junit-platform-engine - 7.8.1

πŸ”¬ How could we reproduce it?

Cucumber Test as described in the documentation

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.proxym.bankerise.backend.messagecenter.domain")
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@Active")
public class MessageCenterApplicationIT {

}

StepsFile

@CucumberContextConfiguration
@SpringBootTest(classes = TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringJUnitConfig
public class MessageCenterSteps {
    @Autowired
    private ApplicationContext applicationContext; // <-- works properly injected

    @MockBean
    private EmailChannelAdapter emailChannelAdapter; <-- not working


This text was originally generated from a template, then edited by hand. You can modify the template here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions