1pom依存関係を追加します
2関連するSpring関連の構成ファイルと関連する.properties構成ファイルを追加します
3JUnitテストクラスを書く
パッケージcom.app.dev.paas; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; インポートjava.util.List; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath *:/ conf / Junit-databaseConfig.xml"、 "classpath *:/ conf / Junit-spring-placeholder.xml"、 "classpath *:/ conf / Junit-Userdao.xml " 、" classpath *:com / yqbsoft / * / ** / cache / springxml / applicationContext-service.xml "}) @WebAppConfiguration public class JUnitTester { @Autowired UmUserMapper umUserMapper; @Autowired DisCache disCache; @BeforeClass public static void init(){ // ApplicationContext content = new ClassPathXmlApplicationContext( "classpath:* / applicationContext.xml"); // osOAuthEnvService = content.getBean(OsOAuthEnvService.class); } @Test public void testPutOne()throws InterruptedException { List <UmUser> users = umUserMapper.query(null); 文字列var = disCache.get( "OsOAuthEnv-oauthEnvMat"); System.out.println( "システム试売"); } }
予防:
正常なテスト: