【发布时间】:2021-11-20 06:00:30
【问题描述】:
如何创建一个空的测试类,如果运行mvn test,它应该返回Tests run: 0, Failures: 0, Errors: 0, Skipped: 0?现在没有任何测试mvn 报告no tests to run。我正在开发一个演示 jenkins 管道,脚本希望所有项目都返回 Tests run: 0 or more。
[INFO] --- maven-surefire-plugin:2.4.2:test (default-test) @ demo-web ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.535 s
[INFO] Finished at: 2021-09-27T09:04:22Z
[INFO] ------------------------------------------------------------------------
[Pipeline] script
我尝试创建一个测试类,但它返回 1 个测试结果。我想要零测试结果。
BanksMvcControllerTest.java
package com.WebDemo.Controller;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.webDemo.WebApplication;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WebApplication.class)
@WebAppConfiguration
public class BanksMvcControllerTest {
@Test
public void contextLoads() {
}
}
【问题讨论】:
-
afaik 你不能。您要么有 1 个运行的测试,要么有 1 个被忽略的测试。所以不,你不能将所有的计数器都设置为 0。
-
哦,好吧。我期待从 asnwer stackoverflow.com/a/69334020/13410618 得到这样的东西
-
不。所以要么写一个测试,要么跳过它,但它会导致在一个地方输出 1。如果什么都没有,您会收到您现在收到的消息(不确定这是否可配置)。但是为什么不只进行一次测试,它会遵守你的 CI 规则......
标签: java spring spring-boot junit