SpringBoot单元测试


@SpringBootTest

测试类需要添加@SpringBootTest注解
@SpringBootTest(classes = 启动类.class)

@SpringBootTest
class TestApplicationTests {

    @Test
    void contextLoads() {
    }

}

启动类

package metadata.before.handle.webspider;


//import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.stereotype.Indexed;

@Indexed
//@MapperScan(basePackages = "metadata.before.handle.webspider.mapper")
@SpringBootApplication
public class WebSpiderApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebSpiderApplication.class,args);
    }
}

测试类

package metadata.before.handle.server.test;

import metadata.before.handle.webspider.WebSpiderApplication;
import metadata.before.handle.webspider.controller.NstlController;
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 java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {
        WebSpiderApplication.class,
})
public class NstlControllerTest {

    @Autowired
    private NstlController nstlController;


    @Test
    public void reapTest() {


        this.nstlController.reap();


    }

}

文章作者: zrh
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 zrh !
  目录