欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

maven項(xiàng)目test執(zhí)行main找不到資源文件的問(wèn)題及解決

 更新時(shí)間:2022年03月08日 11:56:08   作者:誡圣  
這篇文章主要介紹了maven項(xiàng)目test執(zhí)行main找不到資源文件的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

maven項(xiàng)目test執(zhí)行main找不到資源文件

在test下直接執(zhí)行main方法會(huì)導(dǎo)致找不到資源文件,發(fā)現(xiàn)是Test output path下的目錄沒(méi)有資源文件,導(dǎo)致加載不到。

在pom.xml中配置

增加以下配置后執(zhí)行test目錄下的main方法成功

<build>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>${project.basedir}/src/main/resources</directory>
            </testResource>
        </testResources>
</build>

maven項(xiàng)目test編寫

在maven項(xiàng)目中,可以在編譯時(shí)對(duì)一些模塊做測(cè)試。

項(xiàng)目目錄為src/test/java

如下代碼

public class TestProperties {?
?? ?@Test
?? ?public void testProperties() {
?? ??? ?JMproperties properties = new JMproperties();?? ??? ?
?? ??? ?Assert.assertEquals("123456", properties.getDbPwd());
?? ?}
}

這是測(cè)試我的JMproperties類,類里面是一些配置參數(shù)。在這里我測(cè)試是得到的DB密碼是否為123456

測(cè)試

mvn clean test

測(cè)試通過(guò)。若把123456改為12345

結(jié)果如下:

Failed tests:   testProperties(com.test.testproperties.TestProperties): expected:<12345[]> but was:<12345[6]>

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.600s
[INFO] Finished at: Tue Jul 01 14:56:24 CST 2014
[INFO] Final Memory: 26M/258M
[INFO] ------------------------

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論