![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JUnit
行躬
纸上得来终觉浅,绝知此事要躬行。
展开
-
JUnit超时测试示例-计算圆周率
PI类用于计算圆周率package com.xurong.ChaoShiTest;public class PI { //PI = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ... public double calculate(int count) { double sum = 0; boolean positive = true; int n = 0; for (int i = 1;;i += 2) { sum = sum + (positive ? 1.原创 2021-09-22 14:37:59 · 106 阅读 · 0 评论 -
JUnite异常测试-示例
Calculator类package com.xurong.sample;import java.util.Arrays;public class Calculator { public int calculate(String expression) { if (expression == null) {//增加此判断条件,是为了满足抛出的异常是NumberFormatException异常 throw new NumberFormatException("Expression is原创 2021-09-15 21:57:44 · 202 阅读 · 0 评论 -
JUnite中@Beforeclass,@Before,@Test,@After,@Afterclass执行顺序
package com.xurong.sample;import org.junit.After;import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;public class SequenceTest { @BeforeClass public static void setUpBeforeClass() throws Exceptio原创 2021-09-15 16:10:22 · 190 阅读 · 0 评论 -
在Before方法中实例化对象,接下来的测试不需要实例化对象,并且实例化对象的状态不会传递给下一个Test
Calculator类package com.xurong.sample;import java.util.Arrays;public class Calculator { public int calculate(String expression) { String[] ss = expression.split("\\+");//以+号进行分割 System.out.println(expression + " => " + Arrays.toString(ss)); i原创 2021-09-15 16:03:36 · 92 阅读 · 0 评论