启动类org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit.jupiter junit-jupiter-engine test org.junit.vintage junit-vintage-engine test org.junit.platform junit-platform-launcher test junit junit test
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class StartApplication {
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
}
测试类
1、 @SpringBootTest(classes = StartApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 用来指定启动类
2、 @RunWith(SpringRunner.class) 指定用SpringRunner来运行
import mpTest.StartApplication;
import mpTest.entity.User;
import mpTest.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@SpringBootTest(classes = StartApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class MPContextTest {
@Test
public void contextLoads() {
System.out.println(("----- selectAll method test 测试查询所有用户方法 ------"));
System.out.println("----------test--------------");
}
}
关于InvalidTestClassError报错
测试报错
解决方案org.junit.runners.model.InvalidTestClassError: Invalid test class ‘XXX’:
- No runnable methods
- @Test导入错误,应该使用
import org.junit.Test;
- 声明未加public,应该使用
@Test
public void contextLoads() {
}



