关于junit4和junit5的使用方法

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());
    }

}

 

posted @ 2020-08-07 19:02  shouyaya  阅读(1245)  评论(0编辑  收藏  举报