关于mvn命令引用springboot配置
在pom.xml中配置一个profile
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
</profiles>
然后就有了一个activatedProperties值为test,在application.yml中配置:
spring:
profiles:
active: :@activatedProperties@
最后通过mvn clean package -P test引用这个id为test的profile就行了。
关于mvn调用JUnit执行测试并生成报告的问题
- 测试类须以Test开头或结尾,或以TestCase开头或结尾
关于mvn命令引用不同的testng.xml
配置一个properties:
<properties>
<suiteXmlFile>test.xml</suiteXmlFile>
</properties>
然后在surefire中引用此属性:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<!-- 加入编码设置,否则生成的报告会中文乱码-->
<argLine>-Dfile.encoding=UTF-8</argLine>
<suiteXmlFiles>
<!-- src/test/java/jim/auto/spcu/testng/test.xml-->
<suiteXmlFile>
${suiteXmlFile}
</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
最后使用mvn -D suiteXmlFile=src/test/java/jim/auto/spcu/testng/test2.xml就即用引用test2.xml了,默认使用配置的test.xml
关于testng出现空指针的问题
- 测试应该继承AbstractTestNGSpringContextTests类
- 配置注解@ContextConfiguration和@SpringBootTest然后运行testng.xml即可
在测试类上使用 @TestExecutionListeners 注释标签,可以引入的监听器包括
DependencyInjectionTestExecutionListener:使得测试类拥有依赖注入特性
DirtiesContextTestExecutionListener:使得测试类拥有更新 applicationContext 能力
TransactionalTestExecutionListener:使得测试类拥有自动的事务管理能力
@SpringBootTest
@ContextConfiguration
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class})
//@Transactional
@Rollback(false)
public class TestM extends AbstractTestNGSpringContextTests {
@Autowired
private HelloService helloService;
@Test(groups = "t1")
public void contextLoads() {
System.out.println("========================================");
System.out.println(helloService.getName());
System.out.println("========================================");
}
}
Refer to
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f7326181875429c3933fc239045c1c20b4e43a735755949a2c3041b8492aaca777346b5637b7ed89ca0a86e7c73f2ffe77692d5a914165895ff09552609c60c655a8ed59bce6a52592de828e821244ca22543dd1b7d40a5754dd6f815266a2e08e49650345&p=8d3fc64ad4dd5aec0cbd9b7d0d1282&newp=9972de12ce904ead08e2977e09489e231610db2151d1d401298ffe0cc4241a1a1a3aecbf22261702d1cf7a6601a54e5ae1f031723d0034f1f689df08d2ecce7e&user=baidu&fm=sc&query=springboot+cucumber+testng&qid=d6c2f6f10005ace7&p1=2
https://www.cnblogs.com/zeng1994/articles/06917ed3b98677fa7a1b0f74de16c3be.html