IDEA中測試類
阿新 • • 發佈:2019-01-31
1. 建立一個目錄,右鍵-- 設定為測試目錄
2. maven專案中,需要重新新增依賴
如果新增失敗,報錯的話,可能是複製過去,報錯,直接複製下面的網址,找到對應的版本去重新拿到依賴的那個
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframewomework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.3.RELEASE</version>
<scope>test</scope>
</dependency>
gradle 專案中:
dependencies { compile spring_core,spring_web,mybatis compile jdbc,json,logging,apache_commons providedCompile servlet testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group:'org.springframework', name:'spring-test', version:'4.3.3.RELEASE' }
3. 建立的測試類中,添加註釋:(對應的包和註釋,這是放在類前面的)
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:application-context.xml" }) public class TestMeng{ }