spring boot集成testng执行case

Spring boot集成Testng执行测试用例,case中使用的@Resource注解装载bean失败。记录解决办法。

第一步:新建包application,报下创建Application类,如下:

@SpringBootApplication(scanBasePackages = {"cn.szg.*"})
public class Application {

}

 

第二步:新建BaseTest基类,如下:

@SpringBootTest(classes = {Application.class})
public class BaseTest extends AbstractTestNGSpringContextTests{

}

注意:Application.class的包导入一定要保证正确,既上面第一步创建的路径

第三步:

public class UserTest extends BaseTest{
    
    @Autowired
    UserWarpper userWarpper;

    @Test()
    public void getUserInfo() {
        Map paramMap = new HashMap();
        JSONObject result = userWarpper.getUserInfo(paramMap);
        Assert.assertTrue(result.getLongValue("dm_error")==0);
    }
}

 

执行测试结果:

17:16:18.357 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
17:16:18.358 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource 'Inlined Test Properties' with highest search precedence

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

你可能感兴趣的:(spring,boot,testng)