方式一:
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FgwOffensiveApplicationTests {
@Test
public void systemTest() {
System.out.println(“hello world!”);
}
}
方式二:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class methodTest {
@Test
public void add(){
…
}
}
本文介绍了在SpringBoot项目中进行单元测试的两种方法,一种使用JUnit5,另一种使用JUnit4结合SpringRunner。通过具体示例展示了如何编写测试用例。
2万+

被折叠的 条评论
为什么被折叠?



