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

📄 textlistenertest.java

📁 JUNIT1.4源文件等等 源文件等等 源文件等等 源文件
💻 JAVA
字号:
package org.junit.tests;import java.io.ByteArrayOutputStream;import java.io.OutputStream;import java.io.PrintStream;import junit.framework.TestCase;import org.junit.Test;import org.junit.internal.TextListener;import org.junit.runner.JUnitCore;public class TextListenerTest extends TestCase {		private JUnitCore runner;	private OutputStream results;	private TextListener listener;	@Override	public void setUp() {		runner= new JUnitCore();		results= new ByteArrayOutputStream();		PrintStream writer= new PrintStream(results);		listener= new TextListener(writer);		runner.addListener(listener);	}		public static class OneTest {		@Test public void one() {}	}		public void testSuccess() throws Exception {		runner.run(OneTest.class);		assertTrue(results.toString().startsWith(convert(".\nTime: ")));		assertTrue(results.toString().endsWith(convert("\n\nOK (1 test)\n\n")));	}		public static class ErrorTest {		@Test public void error() throws Exception {throw new Exception();}	}		public void testError() throws Exception {		runner.run(ErrorTest.class);		assertTrue(results.toString().startsWith(convert(".E\nTime: ")));		assertTrue(results.toString().indexOf(convert("\nThere was 1 failure:\n1) error(org.junit.tests.TextListenerTest$ErrorTest)\njava.lang.Exception")) != -1);	}		public static class Slow {		@Test public void pause() throws InterruptedException {			Thread.sleep(1000);		}	}		public void testTime() {		runner.run(Slow.class);		assertFalse(results.toString().contains("Time: 0"));	}		private String convert(String string) {		OutputStream resultsStream= new ByteArrayOutputStream();		PrintStream writer= new PrintStream(resultsStream);		writer.println();		return string.replace("\n", resultsStream.toString());	}	}

⌨️ 快捷键说明

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