zoukankan      html  css  js  c++  java
  • 使用Spring boot、testng输出ExtentReports报告不能启动Spring boot

    将需要执行的测试用例全部准备好之后,相对应的testng配置也配置好,启动testng时,发现注入的实例全部都是null,根本没法用,一直报错

    报错情况如下:

    后面经大神指点,加入启动Spring的方法:

    首先在Application中加入方法

    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
    import org.springframework.core.io.ClassPathResource;
    
    
    @SpringBootApplication(exclude = MongoAutoConfiguration.class)
    @MapperScan(basePackages="com.example.demo.dao")
    @Configuration
    public class Application {
        public static boolean started = false;
        private static ApplicationContext applicationContext;
    
        public static ApplicationContext get(){
            return applicationContext;
        }
        public static void main(String[] args) {
            applicationContext = SpringApplication.run(Application.class, args);
            started = true;
        }
    }

    然后在测试用例代码中加入调用启动Spring boot的方法

     public static ApplicationContext applicationContext;
        @BeforeClass
        public void start(){
            if(!Application.started){
                applicationContext = SpringApplication.run(Application.class);
                Application.started = true;
            }else{
                applicationContext = Application.get();
            }
        }

    这样就可以正常启动Spring boot了

  • 相关阅读:
    Qt passwd echoMode placeholer QString.trimmed()
    bit opt
    Linux Kernel Development系统调用
    Linux Kernel Development——列出系统中所有的进程
    Linux Kernel Development——内存管理
    Linux Kernel Development——定时器和时间管理
    Linux Kernel Development——内核同步方法
    [转]Linux 2.6中断下半部机制分析
    Linux Kernel Development——中断
    Linux Kernel Development——虚拟文件系统
  • 原文地址:https://www.cnblogs.com/biyuting/p/11184334.html
Copyright © 2011-2022 走看看