android单元测试-JUnit框架的使用-第一个用例

    xiaoxiao2022-07-02  127

    1.待测试代码

    package com.example.androietest; public class Calculator { public int add(int a ,int b){ return a+b; } public int multiplication(int a, int b){ return a*b; } }

    2.测试代码

    package com.example.androietest; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; public class CalculatorTest { private Calculator mCalculator; @Before public void setUp() { mCalculator = new Calculator(); } @Test public void testAdd(){ assertEquals(4, mCalculator.add(2,2)); } @Test public void testCheng(){ assertEquals(6, mCalculator.multiplication(2,3)); } }

    运行结果

    最新回复(0)