testthread.java

来自「一些关于软件质量保证与测试的资料」· Java 代码 · 共 41 行

JAVA
41
字号
import junit.framework.*;


class DelayedHello implements Runnable {
	private int count;
	private Thread worker;
	public DelayedHello(int count) {
		this.count = count;
		worker = new Thread(this);
		worker.start();
	}
	public void run() {
		try {
			Thread.sleep(count);
			System.out.println("Delayed Hello World");
		} catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
}

public class TestThread extends TestCase {
	private Runnable runnable;	
	 

	public void testExampleThread() throws Throwable {
		System.out.println("Hello, World"); //1
		runnable = new DelayedHello(500); //2
		System.out.println("Goodbye, World"); //3
	}

	public static void main (String[] args) {
		
		junit.textui.TestRunner.run(TestThread.class);
	}
	public static Test suite() {
		return new TestSuite(TestThread.class);
	}
}

⌨️ 快捷键说明

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