maven无法从命令行检测到测试。

huangapple go评论75阅读模式
英文:

maven does not detect tests from the command line

问题

我有一个Spring MVC项目(Java平台的应用程序框架和控制反转容器),其中包含以下测试代码:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {
    "classpath:servlet.xml"
})
public class PastisControllerTests {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {

        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    @Test
    public void should_WhenParams_OK() throws Exception {

        mockMvc.perform(get("/user/2")
                .param("date", "01122020")
                .param("organisationId", "9")
                .contentType(APPLICATION_JSON))
                .andExpect(status().isOk());
    }
    ..
}

但是当我从命令行运行mvn test时,没有执行任何测试。

英文:

I have a Spring MVC project (an application framework and inversion of control container for the Java platform) with this test:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {
		"classpath:servlet.xml"
})
public class PastisControllerTests {

	@Autowired
	private WebApplicationContext wac;

	private MockMvc mockMvc;

	@Before
	public void setup() {

		this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
	}

	@Test
	public void should_WhenParams_OK() throws Exception {

		mockMvc.perform(get("/user/2")
				.param("date", "01122020")
				.param("organisationId", "9")
				.contentType(APPLICATION_JSON))
				.andExpect(status().isOk());
	}
..
}

but when I run mvn test from the command line, no test is executed

答案1

得分: 0

问题在这里:PastisControllerTestsTest,而不是Tests,是您需要的名称组件,以便Maven可以直接识别它。否则,您需要覆盖surefire插件的行为

英文:

The problem is here: PastisControllerTests Test, not Tests, is the name component you need for Maven to recognize it out of the box. Otherwise, you need to override the surefire plugin's behavior.

huangapple
  • 本文由 发表于 2020年10月7日 21:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64244656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定