Junit使用

重点:
1.error 发生异常(可能是一个潜在的bug)
assertEquals(5, new Calulate().div(4,0))
2.failure bug(没有达到预期目标)
assertEquals(5, new Calulate().div(4,1))
在这里插入图片描述
在这里插入图片描述

常用注解

Junit API提供

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

import com.popoaichuiniu.intentGen.Intent;
import com.popoaichuiniu.intentGen.IntentExtraKey;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertTrue;

/**
 * Intent Tester.
 *
 * @author <Authors name>
 * @version 1.0
 * @since <pre>Nov 12, 2018</pre>
 */

@RunWith(Parameterized.class)
public class IntentTest {

    private Intent intent1;
    private Intent intent2;
    private boolean expected;

    public IntentTest(Intent intent1, Intent intent2, boolean expected) {
        this.intent1 = intent1;
        this.intent2 = intent2;
        this.expected = expected;
    }

    @Before
    public void before() throws Exception {


    }

    @After
    public void after() throws Exception {
    }

    /**
     * Method: equals(Object o)
     */
    @Test
    public void testEquals() throws Exception {
//TODO: Test goes here...

        System.out.println("testEquals");
    }

    /**
     * java
     * <p>
     * Method: equivExtraTo(Set<IntentExtraKey> set1, Set<IntentExtraKey> set2)
     */
    @Test
    public void testEquivExtraTo() throws Exception {

        System.out.println("testEquivExtraTo");
//TODO: Test goes here... 
    }

    /**
     * Method: equivCategoryTo(Set<String> cateSet1, Set<String> cateSet2)
     */
    @Test
    public void testEquivCategoryTo() throws Exception {
//TODO: Test goes here...
        System.out.println("testEquivCategoryTo");
    }

    /**
     * Method: hashCode()
     */
    @Test
    public void testHashCode() throws Exception {
//TODO: Test goes here...
        System.out.println("testHashCode");
    }

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

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

    /**
     * Method: contains(Intent intent)
     */
    @Test
    public void testContains() throws Exception {

        if (expected != intent1.contains(intent2)) {
            Assert.fail();
        }

        System.out.println("hello");


//TODO: Test goes here...
    }


    @Parameterized.Parameters
    public static Collection<Object[]> data() {

        Intent intent1 = new Intent();
        Intent intent2 = new Intent();
        boolean expected = true;

        Intent intent11 = new Intent();
        Intent intent22 = new Intent();
        intent11.action="ttt";
        boolean expectedd = true;


        Intent intent111 = new Intent();
        Intent intent222 = new Intent();
        intent222.action="zzz";
        boolean expecteddd = false;


        Intent intent4 = new Intent();
        Intent intent5 = new Intent();
        intent4.categories.add("sss");
        boolean expected4 = true;


        Intent intent44 = new Intent();
        Intent intent55 = new Intent();
        intent55.categories.add("sss");
        boolean expected44 = false;



        Intent intent66=new Intent();
        Intent intent77=new Intent();
        intent66.myExtras.add(new IntentExtraKey("xxx","string","ttt"));
        boolean expected66 = true;


        Intent intent666=new Intent();
        Intent intent777=new Intent();
        intent777.myExtras.add(new IntentExtraKey("xxx","string","ttt"));
        boolean expected666 = false;

        return Arrays.asList(new Object[][]{
               {intent1, intent2, expected},
                {intent11, intent22, expectedd},
                {intent111, intent222, expecteddd},

                {intent4,intent5,expected4},
                {intent44,intent55,expected44},

                {intent66,intent77,expected66},

                {intent666,intent777,expected666}


        });

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值