欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

测试springboot项目出现Test Ignored的解决,

来源: javaer 分享于  点击 4654 次 点评:245

测试springboot项目出现Test Ignored的解决,


目录
  • 测试springboot项目出现Test Ignored
  • 测试类不报错只提示Test ignored的解决

测试springboot项目出现Test Ignored

今天在写springBoot项目运行测试类时出现了以下问题:

Test ignored.
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

在这里插入图片描述

原因是我在建包时把启动类放到了servlet包下,如图

在这里插入图片描述

需要把这个启动目录放到根目录下,移出来问题就解决了

测试类不报错只提示Test ignored的解决

在点击运行测试方法后出现如下错误:

解决方法:

在这个位置需要有一个Java类,名字可以随便写。

类里面这样写:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class);//MyApp为你的启动类的名称 如下图
    }
}

这相当于一个程序的入口,名字可以随便起,但是一定得有。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持3672js教程。

您可能感兴趣的文章:
  • 解决@SpringBootTest 单元测试遇到的坑
  • SpringBootTest--踩坑错误的解决
  • SpringBootTest单元测试报错的解决方案
  • SpringBoot Test类注入失败的解决
相关栏目:

用户点评