maven項目test執(zhí)行main找不到資源文件的問題及解決
maven項目test執(zhí)行main找不到資源文件
在test下直接執(zhí)行main方法會導致找不到資源文件,發(fā)現(xiàn)是Test output path下的目錄沒有資源文件,導致加載不到。
在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項目test編寫
在maven項目中,可以在編譯時對一些模塊做測試。
項目目錄為src/test/java
如下代碼
public class TestProperties {? ?? ?@Test ?? ?public void testProperties() { ?? ??? ?JMproperties properties = new JMproperties();?? ??? ? ?? ??? ?Assert.assertEquals("123456", properties.getDbPwd()); ?? ?} }
這是測試我的JMproperties類,類里面是一些配置參數(shù)。在這里我測試是得到的DB密碼是否為123456
測試
mvn clean test
測試通過。若把123456改為12345
結果如下:
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] ------------------------
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
常用校驗注解之@NotNull,@NotBlank,@NotEmpty的區(qū)別及說明
這篇文章主要介紹了常用校驗注解之@NotNull,@NotBlank,@NotEmpty的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01IDEA整合SSM框架實現(xiàn)網(wǎng)頁上顯示數(shù)據(jù)
最近做了個小項目,該項目包在intellij idea中實現(xiàn)了ssm框架的整合以及實現(xiàn)訪問,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05