Spring Boot项目中,新添加test类,使用@RunWith注解报错,肯定是项目中没有添加依赖。

 解决办法:

        1.pom.xml引入依赖

<!--添加junit环境的jar包-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

        2.在测试类使用注解,并导入依赖

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = {CommunityApplication.class})//CommunityApplication是我项目的启动类
public class TestSecurityUtils {

    @Test
    public void test01() {
        String password = SecurityUtils.encryptPassword("123456");
        System.out.println(password);

    }

}

注意:一定要在方法上加上@Test,否则会报错junit:no runnable methods 


版权声明:本文为susu1083018911原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/susu1083018911/article/details/121332216