Skip to content

@BeforeSuite cannot autowire MockMvc #2191

@cenyu00

Description

@cenyu00

TestNG Version

Note: only the latest version is supported
7.0.0

Expected behavior

autowire MockMvc in springboot project

Actual behavior

cannot autowire MockMvc in springboot project

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

Please, share the test case (as small as possible) which shows the issue

in springboot 2.1.7 project.
I test HTTP RESTful in controller layer, use MockMvc mock HTTP Request。
in @Test annotation method ,this MockMvc can be autowire,but,in @BeforeSuite annotation method, the MockMvc is null.

this class:

@SpringBootTest(classes = DmsServerApplication.class,
        webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureMockMvc
public class MetaTest extends AbstractTestNGSpringContextTests {

    @Autowired
    private MockMvc mockMvc;


    @BeforeSuite
    public void setUp() throws Exception {
        // mock request http

    }

}

what can i do ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions