解决:ApplicationTest does not declare any static, non-private, non-final, nested classes annotated wit

这是在运行测试类的时候提示报错信息;
原因是没有把启动类写好或者是没有配置启动类;
解决如下,
先是要正常写好启动类;
然后把启动类添加到运行的测试类,添加到这个地方:@SpringBootTest;
有两种填写方式,一种是:@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

还有一种是网上反馈的方法:
@SpringBootTest(classes = {启动类.class })//这里加启动类

package com.itheima;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.itheima.domain.Person;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTest {
    @Autowired
    private Person person;

    @Test
    public void contextLoads() {
        System.out.println(person);
    }
}

 

上一篇:【Leetcode刷题笔记】 单调栈


下一篇:LeetCode-30-串联所有单词的子串