您的位置:首页 > 其它

idea 基于junit测试和自动生成测试类

2016-09-18 00:00 549 查看
①之前一直用myeclipse开发,习惯了junit测试。现在用idea开发,不能够测试,太不方便了,发现用@Test识别不了。于是查了poem.xml,发现我的mven里面的jar包版本不对。

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

junit3 基于 继承TextCase

junit 4 集成了@Text注释

所以直接引入jar 包,版本改为4.10即可。

jar包下载地址:

http://download.csdn.net/download/gongweijiao/3783442

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

idea 可以引入 JunitGenerator插件 自动生成测试代码

②引入方式:

preference--->Plugins--->搜索框搜索JunitGenerator--->右键upload--->restart

即可

③测试

找到类以后

command+n ---->junit text --->junit4 即可

测试结果(自动生成)

public class CoachDaoImplTest {
@Before
public void before() throws Exception {
}

@After
public void after() throws Exception {
}

/**
*
* Method: saveCoach(CoachInfo coachInfo)
*
*/
@Test
public void testSaveCoach() throws Exception {
//TODO: Test goes here...
}

/**
*
* Method: queryTrain(String level, String coachName, String siteProvince, Date start, Date end, String certNumber, String orderName, Integer orderBy, Integer page, Integer rows)
*
*/
@Test
public void testQueryTrain() throws Exception {
//TODO: Test goes here...
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息