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

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM