1.junit4的基本使用方法:(轉載至:https://my.oschina.net/lenglingx/blog/4326787)
@RunWith(SpringRunner.class) @SpringBootTest class TaskRepositoryTest2 { @Autowired private TaskRepository taskRepository; @Test void test() { Optional<Task> task = taskRepository.findById((long) 1); System.out.println("Task:: " + task.get()); } }
2.junit5的基本使用方法(springboot 2.3后junit版本升級為5,應側重用如下寫法):
@ExtendWith(SpringExtension.class) @SpringBootTest @DisplayName("TaskRepositoryTest") class TaskRepositoryTest { @Autowired private TaskRepository taskRepository; @Test @DisplayName("新junit測試1") void test() { Optional<Task> task = taskRepository.findById((long) 1); System.out.println("Task:: " + task.get()); } }
