Junit4-No tests found matching Tests from org.junit.runner.Request
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = {SpringConfig.class})public class SpringTest {// ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");// AccountService accountService = (AccountService) classPathXmlApplicationContext.getBean("accountService");// AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);// AccountService accountService = (AccountService) annotationConfigApplicationContext.getBean("accountService"); @Autowired private AccountService accountService; @Test public void testSave(){ Account account = new Account(); account.setName("乌冬面"); account.setMoney(7777); accountService.save(account); } @Test public void testUpdate(){ Account account = new Account(); account.setName("希宝"); account.setId(7); accountService.update(account); } @Test public void testDelete(){ Account account = new Account(); account.setId(8); accountService.delete(account); } @Test public void testFindAll(){ List<Account> all = accountService.findAll(); for (Account account : all) { System.out.println(account); } } @Test public void testFindById(){ Account account = accountService.findById(6); System.out.println(account); } public void test(){ }}
在上述代码编写实现后, 点击运行其中一个测试方法,就会报题目中的谬误
解决形式是:
先运行整个测试类, 胜利后, 再运行其中一个测试方法
另,
导包应该导的是import org.junit.Test
,不能导import org.junit.jupiter.api.Test