欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

IDEA中测试类

程序员文章站 2024-03-24 19:12:34
...

1.  创建一个目录,右键--  设置为测试目录

IDEA中测试类

 

 

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{  }
相关标签: 测试类