spring專案實現單元測試過程解析
阿新 • • 發佈:2020-01-07
後臺開發過程中,寫單元測試是非常重要的,對於我們開發人員除錯、排查問題是很方便的,
但是我們在啟動專案的時候,需要將所以類交給spring託管,在單元測試中需要怎麼實現類的注入呢?
直接上圖
繼續上程式碼
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; <br data-filtered="filtered">@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={ "classpath:application-context.xml","classpath:application-database.xml","classpath:application-redis.xml"}) public class PartRelevanceTest { @Resource private PartRelevanceMapper partRelevanceMapper; @Test public void selectTypeNumOne() { PartRelevanceTypeNum record = new PartRelevanceTypeNum(); record.setRelCode("2222112"); record.setType("2"); PartRelevanceTypeNum typeNum = partRelevanceMapper.selectTypeNumOne(record); System.out.println(typeNum==null?"typeNum-資料為空":typeNum.toString()); } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。