idea junit4 单元测试

提醒:测试单元中的每一个方法必须独立测试,每个测试方法之间不能有依赖。

实体类:

package Gg;

/**
 * Created by ASUS on 2016/12/5.
 */
public class FF {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void toString(String name){
        this.name=name;
        System.out.println("name");
    }
}

创建好实体类FF后,在idea中导入junit插件,在FF.class中Alt+Inset,这样会出现一个test包下的


package test.Gg; 

import Gg.FF;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Before; 
import org.junit.After; 

/** 
* FF Tester. 
* 
* @author <Authors name> 
* @since 
* @version 1.0 
*/ 
public class FFTest { 

@Before
public void before() throws Exception { 
} 

@After
public void after() throws Exception { 
} 

/** 
* 
* Method: getName() 
* 
*/ 
@Test
public void testGetName() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: setName(String name) 
* 
*/ 
@Test
public void testSetName() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: toString(String name) 
* 
*/ 
@Test
public void testToString() throws Exception { 
//TODO: Test goes here...
    FF ff= new FF();
    ff.setName("sff");
    Assert.assertEquals("sff123", ff.getName());
} 


} 
然后可以点击运行一个函数、或一整个test类

点击左边的按钮,就只运行testToString()一个方法,结果为


代码覆盖率的html页面为:


测试结果html页面:



也可以运行整个test类


参考资料:JUnit单元测试--IntelliJ IDEA


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值