One, download the jar package
Link: https://pan.baidu.com/s/1FzBoZbyGXo6sgG726CBazQ
Extraction code: rmgh
Two, add the jar package to the project
Three, write test cases, test classes
public class Calculator {
/**
* 加法
*
* @param a
* @param b
* @return a + b
*/
public int add(int a, int b) {
return a + b;
}
/**
* 减法
* @param a
* @param b
* @return a - b
*/
public int sub(int a, int b) {
return a - b;
}
}
Test class
import com.sky.junit.Calculator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class CalculatorTest {
/**
* 初始化方法
* 用于资源申请,所有测试方法在执行之前都会先执行该方法
*/
@Before
public void init() {
System.out.println("init....");
}
/**
* 释放资源方法,所有测试方法在执行完之后,都会执行该方法
*/
@After
public void close() {
System.out.println("close...");
}
/**
* 测试add方法
*/
@Test
public void testAdd() {
System.out.println("我被执行了");
Calculator calculator = new Calculator();
int result = calculator.add(1, 2);
System.out.println(result);
//用断言操作来处理结构(逾期值,结果值)
Assert.assertEquals(3, result);
}
}
Fourth, download the plug-in to automatically generate test cases
After downloading Apply, ok
1. Setting:
Output path:
S O U R C E P A T H / . . / t e s t / {SOURCEPATH}/../test/ SOURCEPATH/../test/{PACKAGE}/${FILENAME}
2. Create a new test folder equal to src under the module
3. Modify the coding problem
4. Modify the JUnit configuration file
5. Automatically generate test classes