本文整理汇总了Java中junit.framework.TestResult类的典型用法代码示例。如果您正苦于以下问题:Java TestResult类的具体用法?Java TestResult怎么用?Java TestResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestResult类属于junit.framework包,在下文中一共展示了TestResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkFailures
import junit.framework.TestResult; //导入依赖的package包/类
public static void checkFailures(TestCase test, TestResult res, String workDirPath) {
StringBuffer t = text;
if (t == null) {
return;
}
synchronized (t) {
if (t.length() > 0) {
StringBuilder sb = new StringBuilder();
sb.append("NbModuleSuite has been started with failOnMessage(");
sb.append(msg);
sb.append(") and failOnException(").append(exc);
sb.append("). The following failures have been captured:\n");
sb.append(normalize(text, workDirPath));
res.addFailure(test, new AssertionFailedError(sb.toString()));
t.setLength(0);
}
}
}
示例2: run
import junit.framework.TestResult; //导入依赖的package包/类
/**
* Runs the test case, while conditionally skip some according to result of
* {@link #canRun} method.
*/
@Override
public void run(final TestResult result) {
if (canRun()) {
System.setProperty("netbeans.full.hack", "true"); // NOI18N
System.setProperty("java.util.prefs.PreferencesFactory",
MemoryPreferencesFactory.class.getName());//NOI18N
try {
Preferences.userRoot().sync();
} catch(BackingStoreException bex) {}
Level lev = logLevel();
if (lev != null) {
Log.configure(lev, logRoot(), NbTestCase.this);
}
super.run(result);
}
}
示例3: testRuntimeExceptionsAlsoGenerateLog
import junit.framework.TestResult; //导入依赖的package包/类
public void testRuntimeExceptionsAlsoGenerateLog() throws Exception {
if (throwIt != null) {
Logger.getLogger("").info("Ahoj");
throw throwIt;
}
FlowControlTest l = new FlowControlTest("testRuntimeExceptionsAlsoGenerateLog");
l.throwIt = new NullPointerException();
TestResult res = l.run();
assertEquals("No failures", 0, res.failureCount());
assertEquals("One error", 1, res.errorCount());
Object o = res.errors().nextElement();
TestFailure f = (TestFailure)o;
if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Ahoj") == -1) {
fail("Logged messages shall be in exception message: " + f.exceptionMessage());
}
}
示例4: testTestReuseUsedir
import junit.framework.TestResult; //导入依赖的package包/类
public void testTestReuseUsedir(){
NbTestSuite instance = new NbTestSuite();
instance.addTest(
NbModuleSuite.emptyConfiguration().gui(false)
.addTest(NbModuleSuiteTimestamps.class)
.enableClasspathModules(false)
.suite());
instance.addTest(
NbModuleSuite.emptyConfiguration().gui(false)
.addTest(NbModuleSuiteTimestamps.class)
.reuseUserDir(true)
.enableClasspathModules(false)
.suite());
TestResult res = junit.textui.TestRunner.run(instance);
assertEquals("Two tests started", 2, res.runCount());
assertEquals("No failures", 0, res.failureCount());
assertEquals("No errors", 0, res.errorCount());
String value = System.getProperty("stamps");
assertNotNull("Property provided", value);
}
示例5: testJustRunTestCase
import junit.framework.TestResult; //导入依赖的package包/类
public void testJustRunTestCase() {
class Fail extends NbTestCase {
public Fail() {
super("testFail");
}
public void testFail() {
throw new IllegalStateException();
}
}
Fail f = new Fail();
TestResult res = new TestResult();
f.run(res);
assertEquals("One error", 1, res.errorCount());
}
示例6: testThatTheTimeOutStillPrintsTheWarning
import junit.framework.TestResult; //导入依赖的package包/类
public void testThatTheTimeOutStillPrintsTheWarning() throws Exception {
TimeOutHasToPrintLogTest t = new TimeOutHasToPrintLogTest("printAhojAndTimeOut");
CharSequence seq = Log.enable(LOG.getName(), Level.FINE);
TestResult res = t.run();
assertEquals("One test has been run", 1, res.runCount());
String s = seq.toString();
if (s.indexOf("Ahoj") == -1) {
fail("Ahoj has to be logged:\n" + s);
}
assertEquals("No error", 0, res.errorCount());
assertEquals("One failure", 1, res.failureCount());
TestFailure f = (TestFailure)res.failures().nextElement();
s = f.exceptionMessage();
if (s.indexOf("Ahoj") == -1) {
fail("Ahoj has to be part of the message:\n" + s);
}
}
示例7: testThreadDumpPrinted
import junit.framework.TestResult; //导入依赖的package包/类
public void testThreadDumpPrinted() throws Exception {
TimeOutHasToPrintLogTest t = new TimeOutHasToPrintLogTest("justTimeOutInOneOfMyMethods");
TestResult res = t.run();
assertEquals("One test has been run", 1, res.runCount());
TestFailure failure = (TestFailure)res.failures().nextElement();
String s = failure.exceptionMessage();
if (s.indexOf("justTimeOutInOneOfMyMethods") == -1) {
fail("There should be thread dump reported in case of timeout:\n" + s);
}
assertEquals("No error", 0, res.errorCount());
assertEquals("One failure", 1, res.failureCount());
}
示例8: testLoggingAndTimeOut
import junit.framework.TestResult; //导入依赖的package包/类
public void testLoggingAndTimeOut() throws Exception {
TestResult result = new TestResult();
T t = new T("testLoadFromSubdirTheSFS");
t.run(result);
assertEquals("No error", 0, result.errorCount());
assertEquals("One failure", 1, result.failureCount());
Object o = result.failures().nextElement();
String output = o.toString();
if (output.indexOf("LogAndTimeOutTest$T") == -1) {
fail("There should be a stacktrace:\n" + output);
}
if (output.indexOf("Adding 5") == -1) {
fail("There should be a 'Adding 5' message:\n" + output);
}
}
示例9: testMyExceptionIsWrappedWithLogMsg
import junit.framework.TestResult; //导入依赖的package包/类
public void testMyExceptionIsWrappedWithLogMsg() throws Exception {
LoggingTest inner = new LoggingTest("throwMyThrowable");
class MyEx extends Exception {
}
inner.toThrow = new MyEx();
TestResult res = inner.run();
assertEquals("One error", 1, res.errorCount());
assertEquals("No failure", 0, res.failureCount());
TestFailure f = (TestFailure)res.errors().nextElement();
if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Going to throw") == -1) {
fail("There should be output of the log:\n" + f.exceptionMessage());
}
}
示例10: testMyExceptionWithStackTrace
import junit.framework.TestResult; //导入依赖的package包/类
public void testMyExceptionWithStackTrace() throws Exception {
LoggingTest inner = new LoggingTest("throwMyThrowable");
class MyEx extends Exception {
}
inner.toThrow = new MyEx();
inner.toMsg = new MyEx();
TestResult res = inner.run();
assertEquals("One error", 1, res.errorCount());
assertEquals("No failure", 0, res.failureCount());
TestFailure f = (TestFailure)res.errors().nextElement();
if (
f.exceptionMessage() == null ||
f.exceptionMessage().indexOf("Going to throw") == -1 ||
f.exceptionMessage().indexOf("testMyExceptionWithStackTrace") == -1
) {
fail("There should be output of the log:\n" + f.exceptionMessage());
}
}
示例11: testClusterPathFinal
import junit.framework.TestResult; //导入依赖的package包/类
public void testClusterPathFinal() throws Exception {
if (!NbModuleSuiteTest.isCluster("ide")) {
// skip
return;
}
LinkedList<File> clusters = new LinkedList<File>();
NbModuleSuite.S.findClusters(clusters, Collections.singletonList("ide"));
assertFalse("Something found", clusters.isEmpty());
assertEquals("One element found", 1, clusters.size());
final File ideCluster = clusters.get(0);
System.setProperty("cluster.path.final", ideCluster.getPath() + ":" + new File(ideCluster.getParent(), "nonexistent"));
Configuration conf = NbModuleSuite.createConfiguration(NbModuleSuiteClusterPath.class).gui(false).clusters(".*");
Test test = conf.suite();
test.run(new TestResult());
String val = System.getProperty("my.clusters");
assertNotNull("The test was running", clusters);
assertNotNull("Value has been set", val);
assertTrue("ide cluster shall be included: " + val, val.contains(ideCluster.getPath()));
assertFalse("no java cluster shall be included: " + val, val.matches(".*java[:;].*"));
assertFalse("no apisupport cluster shall be included: " + val, val.matches(".*apisupport[:;].*"));
assertFalse("no ergonomics cluster shall be included: " + val, val.matches(".*ergonomics[:;].*"));
}
示例12: iterateTests
import junit.framework.TestResult; //导入依赖的package包/类
private void iterateTests(TestResult result, StringBuffer times, TestSuite suite, AtomicLong min, AtomicLong max) {
Enumeration en = suite.tests();
while (en.hasMoreElements()) {
Test t = (Test)en.nextElement();
if (t instanceof Callable) {
try {
Long v = (Long)((Callable) t).call();
long time = v.longValue();
if (time < min.longValue()) {
min.set(time);
}
if (time > max.longValue()) {
max.set(time);
}
// append(t.toString()).append(" value: ")
times.append("Run: ").append(v).append('\n');
} catch (Exception ex) {
result.addError(this, ex);
}
}
if (t instanceof TestSuite) {
iterateTests(result, times, (TestSuite)t, min, max);
}
}
}
示例13: testRuntimeExceptionsAlsoGenerateLog
import junit.framework.TestResult; //导入依赖的package包/类
public void testRuntimeExceptionsAlsoGenerateLog() throws Exception {
if (throwIt != null) {
Logger.getLogger("global").info("Ahoj");
throw throwIt;
}
LoggingControlTest l = new LoggingControlTest("testRuntimeExceptionsAlsoGenerateLog");
l.throwIt = new NullPointerException();
TestResult res = l.run();
assertEquals("No failures", 0, res.failureCount());
assertEquals("One error", 1, res.errorCount());
Object o = res.errors().nextElement();
TestFailure f = (TestFailure)o;
if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Ahoj") == -1) {
fail("Logged messages shall be in exception message: " + f.exceptionMessage());
}
}
示例14: run
import junit.framework.TestResult; //导入依赖的package包/类
@Override
public void run(TestResult result) {
for(int i = 0; i < ENV.length; i++) {
String contents = (String) ENV[i][0];
String folder = (String) ENV[i][1];
String type = (String) ENV[i][2];
for(int j = 0; j < testCount(); j++) {
Test test = testAt(j);
if (test instanceof ProfilesTrackerTest) {
((ProfilesTrackerTest) test).setEnv(type, folder, contents);
}
}
System.out.println("Running tests for: " + type);
super.run(result);
}
}
示例15: TestResponseWriter
import junit.framework.TestResult; //导入依赖的package包/类
/**
* Creates an XhtmlResponseWriter.
* @param out a Writer to write to
* @param contentType the xhtml content type
* @param encoding the character encoding the Writer uses
*/
public TestResponseWriter(
Writer out,
String contentType,
String encoding,
Test test,
TestResult result) throws UnsupportedEncodingException
{
if (out == null)
throw new NullPointerException();
_out = out;
_encoding = encoding;
_test = test;
_result = result;
CaboHttpUtils.validateEncoding(encoding);
_onlyValidIds = "true".equals(
System.getProperty("org.apache.myfaces.trinidad.TestIdValidity"));
_testBlockLevel = "true".equals(
System.getProperty("org.apache.myfaces.trinidad.TestBlockElementNesting"));
}