⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmultithread.java

📁 一些关于软件质量保证与测试的资料
💻 JAVA
字号:
import junit.framework.*;

import net.sourceforge.groboutils.junit.v1.*;


 class MultiDelayedHello extends TestRunnable {
	private String name;
	public MultiDelayedHello(String name) {
		this.name = name;
	}
	public void runTest() throws Throwable {
		long l;
		l = Math.round(2 + Math.random() * 3);
		// Sleep between 2-5 seconds
		Thread.sleep(l * 1000);
		System.out.println("Delayed Hello World " + name);
	}
}

 
 
public class TestMultiThread extends TestCase {
	private TestRunnable testRunnable;
	
/**在你的测试用例中使用MultiThreadedTestRunner, 
* MTTR需要一个TestRunnable对象做为它的构造器的参数

* MTTR创建以后,调用runTestRunnables()方法来运行它
*/
public void testExampleThread() throws Throwable {

//实例化 TestRunnable 类
	TestRunnable tr1, tr2, tr3;
	tr1 = new MultiDelayedHello("1");
	tr2 = new MultiDelayedHello("2");
	tr3 = new MultiDelayedHello("3");

	//把实例传递给 MTTR
	TestRunnable[] trs = {tr1, tr2, tr3};
	MultiThreadedTestRunner mttr =
		new MultiThreadedTestRunner(trs);
	//执行MTTR和线程
	mttr.runTestRunnables();
}
/**
* 标准的 main() 和 suite() 方法
*/
	public static void main (String[] args) {
		
		junit.textui.TestRunner.run(TestMultiThread.class);
	}
	public static Test suite() {
		return new TestSuite(TestMultiThread.class);
}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -