对unit4测试的初步认知

本次测试是对于unit4测试的简单运用,重在学习。
测试代码是一个For();函数。
运行机制是首先生成一个整形的随机数,然后进行for循环生成i与随机数相等,i返回值result。
测试是比较生成的随机数是否与result相等。
学习难点:
  github作为一种新型的工具,尤其是全英文,学习使用起来特别困难。
项目github地址:https://github.com/lgspath/unit4_test
package unit4_test1; public class Unit_test { private static int result; private static int rrandom; public int Number() { int random = (int) Math.random(); rrandom = random; return rrandom; } public void For() { for (int i = 0; i < rrandom; i++) { result = i; } } public int getResult() { return result; } }

  

package unit4_test1;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class Unit_testTest {
	private static Unit_test unit4_test = new Unit_test();
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testFor() {
		unit4_test.For();
		assertEquals(unit4_test.Number(), unit4_test.getResult());
	}

}

  

原文地址:https://www.cnblogs.com/liguosong/p/4788670.html