SpringBoot Junit MAVEN

写一下最近写单体测试的一些笔记.

SrpingBoot的测试用例:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {ApiApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

如果需要加其他配置, 可以使用SrpingBoot的Configuration, 来引入其他资源, 比如本次就引入了excel作为配置文件.

之所以选择excel,是因为exce可以作为嵌入式数据库来用,编辑数据方便灵活,没有其他嵌入数据库可以与之相比, 可以加入vba编程, 种种好处.本想用MongDB, 还是算了,高冷难用.

-------------

mvn 命令行启动

mvn -Dtest=ApiTestSuit -DfailIfNoTests=false test
mvn test
mvn -Dtest=TestControllerTest#test -DfailIfNoTests=false test

启动目录在root pom所在目录.-Dtest=xxxx的时候, 会去每个子pom所在项目的test中找xxxx的测试, 会报错, 所以需要加上-DfailIfNoTests=false

-------------

https://blog.csdn.net/Joze_3/article/details/75402398

maven在build后会自动去Downloading 这个maven-metadata.xml文件,这个文件可以看作版本信息,作为一个版本比对。
但maven服务器在挂了之后,会一直卡在DOWNLOADING和retry。
解决方案: 本地的maven配置文件settings.xml

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>xxxxx-maven-virtual</name>
        <url>xxxxxxx</url>
    </repository>
    <repository>
        <id>snapshots</id>
        <name>xxx-release-maven-virtual</name>
        <url>xxxxxxx</url>
        <snapshots>
            <enabled>true</enabled>
            <!-- always,never -->
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>xxx-release-maven-virtual</name>
        <url>xxxxxxxx</url>
    </pluginRepository>
    <pluginRepository>
        <id>snapshots</id>    
        <name>xxx-release-maven-virtual</name>
        <url>xxxxxx</url>
        <snapshots>
         <enabled>true</enabled>
            <!-- always,never -->
            <updatePolicy>never</updatePolicy>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

这篇讲得挺好, 简明扼要

https://www.cnblogs.com/liubaozhe/p/6929432.html

-----------------------------------------------------------------------

mvn 命令加上 -DskipTests #,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。
mvn 命令加上 -Dmaven.test.skip=true #,不执行测试用例,也不编译测试用例类。
其中-D的意思是 -D,--define <arg> Define a system property

猜你喜欢

转载自www.cnblogs.com/tekikesyo/p/10510007.html
今日推荐