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);
}
}
}
java类junit.framework.TestResult的实例源码
NbModuleLogHandler.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
NbTestCase.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
FlowControlTest.java 文件源码
项目:incubator-netbeans
阅读 31
收藏 0
点赞 0
评论 0
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());
}
}
NbModuleSuiteStampTest.java 文件源码
项目:incubator-netbeans
阅读 38
收藏 0
点赞 0
评论 0
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);
}
NbTestCaseTest.java 文件源码
项目:incubator-netbeans
阅读 40
收藏 0
点赞 0
评论 0
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());
}
TimeOutHasToPrintLogTest.java 文件源码
项目:incubator-netbeans
阅读 37
收藏 0
点赞 0
评论 0
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);
}
}
TimeOutHasToPrintLogTest.java 文件源码
项目:incubator-netbeans
阅读 34
收藏 0
点赞 0
评论 0
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());
}
LogAndTimeOutTest.java 文件源码
项目:incubator-netbeans
阅读 25
收藏 0
点赞 0
评论 0
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);
}
}
LoggingTest.java 文件源码
项目:incubator-netbeans
阅读 35
收藏 0
点赞 0
评论 0
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());
}
}
LoggingTest.java 文件源码
项目:incubator-netbeans
阅读 44
收藏 0
点赞 0
评论 0
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());
}
}
NbModuleSuiteClusterPathFinalTest.java 文件源码
项目:incubator-netbeans
阅读 31
收藏 0
点赞 0
评论 0
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[:;].*"));
}
Benchmark.java 文件源码
项目:incubator-netbeans
阅读 39
收藏 0
点赞 0
评论 0
public final void run( TestResult result ) {
try {
Method testMethod = getClass().getMethod( name, emptyClassArray );
for( int a=0; a<arguments.length; a++ ) {
result.startTest( this );
try {
doOneArgument( testMethod, arguments[a] );
} catch( AssertionFailedError err ) {
result.addFailure( this, err );
} catch( ThreadDeath td ) {
throw td; // need to propagate this
} catch( Throwable t ) {
result.addError( this, t );
}
result.endTest( this );
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
ExpandFolderTest.java 文件源码
项目:incubator-netbeans
阅读 33
收藏 0
点赞 0
评论 0
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);
}
}
}
LoggingControlTest.java 文件源码
项目:incubator-netbeans
阅读 33
收藏 0
点赞 0
评论 0
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());
}
}
ProfilesTrackerTest.java 文件源码
项目:incubator-netbeans
阅读 46
收藏 0
点赞 0
评论 0
@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);
}
}
TestResponseWriter.java 文件源码
项目:myfaces-trinidad
阅读 41
收藏 0
点赞 0
评论 0
/**
* 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"));
}
RenderKitTestCase.java 文件源码
项目:myfaces-trinidad
阅读 38
收藏 0
点赞 0
评论 0
@Override
public void run(TestResult result)
{
// Cache the TestResult so we can directly add failure without
// aborting the run
_result = result;
CatchSevere catchSevere = new CatchSevere();
Logger apacheLogger = Logger.getLogger("org.apache");
apacheLogger.addHandler(catchSevere);
try
{
RenderKitBootstrap.setFactories(_facesConfigInfo);
super.run(result);
}
finally
{
apacheLogger.removeHandler(catchSevere);
RenderKitBootstrap.clearFactories();
}
}
OsgiJUnitService.java 文件源码
项目:gemini.blueprint
阅读 32
收藏 0
点赞 0
评论 0
/**
* Execute the JUnit test and publish results to the outside-OSGi world.
*
* @param test
* @throws Exception
*/
protected void executeTest(OsgiJUnitTest test) throws Exception {
// create holder
// since we're inside OSGi, we have to use the special loading procedure
OsgiTestInfoHolder holder = HolderLoader.INSTANCE.getHolder();
// read the test to be executed
String testName = holder.getTestMethodName();
if (log.isDebugEnabled()) {
log.debug("Reading test [" + testName + "] for execution inside OSGi");
}
// execute the test
TestResult result = runTest(test, testName);
if (log.isDebugEnabled()) {
log.debug("Sending test results from OSGi");
}
// write result back to the outside world
TestUtils.unpackProblems(result, holder);
}
TestUtils.java 文件源码
项目:gemini.blueprint
阅读 30
收藏 0
点赞 0
评论 0
/**
* Clones the test result from a TestResult loaded through a different
* classloader.
*
* @param source test result loaded through a different classloader
* @param destination test result reported to the outside framework
* @param test initial test used for bootstrapping the integration framework
* @return cloned test result
*/
public static TestResult cloneTestResults(OsgiTestInfoHolder source, TestResult destination, Test test) {
// get errors
for (Throwable throwable : source.getTestErrors()) {
destination.addError(test, throwable);
}
// get failures
// since failures are a special JUnit error, we have to clone the stack
for (Throwable originalFailure : source.getTestFailures()) {
AssertionFailedError clonedFailure = new AssertionFailedError(originalFailure.getMessage());
clonedFailure.setStackTrace(originalFailure.getStackTrace());
destination.addFailure(test, clonedFailure);
}
return destination;
}
AbstractOsgiTests.java 文件源码
项目:gemini.blueprint
阅读 41
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* <p/>
* <p/> Replacement run method. Gets a hold of the TestRunner used for running this test so it can populate it with
* the results retrieved from OSGi.
*/
public final void run(TestResult result) {
// get a hold of the test result
originalResult = result;
result.startTest(osgiJUnitTest);
result.runProtected(osgiJUnitTest, new Protectable() {
public void protect() throws Throwable {
AbstractOsgiTests.this.runBare();
}
});
result.endTest(osgiJUnitTest);
// super.run(result);
}
MultiVmTestSuite.java 文件源码
项目:reladomo
阅读 30
收藏 0
点赞 0
评论 0
public void run(TestResult result)
{
try
{
createSlaveVm();
slaveVm.startSlaveVm(testClass);
super.run(result);
}
catch(RuntimeException e)
{
// we log this here, because junit 3.8 hides this exception
this.logger.error("had a problem running the test", e);
throw e;
}
finally
{
slaveVm.shutdownSlaveVm();
}
}
ExtensionTest.java 文件源码
项目:cacheonix-core
阅读 40
收藏 0
点赞 0
评论 0
public void testRunningErrorsInTestSetup() {
TestCase failure= new TestCase("failure") {
public void runTest() {
fail();
}
};
TestCase error= new TestCase("error") {
public void runTest() {
throw new Error();
}
};
TestSuite suite= new TestSuite();
suite.addTest(failure);
suite.addTest(error);
TestSetup wrapper= new TestSetup(suite);
TestResult result= new TestResult();
wrapper.run(result);
assertEquals(1, result.failureCount());
assertEquals(1, result.errorCount());
}
FunctionalTestClassTestSuite.java 文件源码
项目:cacheonix-core
阅读 34
收藏 0
点赞 0
评论 0
public void run(TestResult testResult) {
if ( testCount == 0 ) {
// might be zero if database-specific...
return;
}
try {
log.info( "Starting test-suite [" + getName() + "]" );
setUp();
testPosition = 0;
super.run( testResult );
}
finally {
try {
tearDown();
}
catch( Throwable ignore ) {
}
log.info( "Completed test-suite [" + getName() + "]" );
}
}
FunctionalTestClassTestSuite.java 文件源码
项目:cacheonix-core
阅读 33
收藏 0
点赞 0
评论 0
public void runTest(Test test, TestResult testResult) {
testPosition++;
if ( environmentSetupError != null ) {
testResult.startTest( test );
testResult.addError( test, environmentSetupError );
testResult.endTest( test );
return;
}
if ( ! ( test instanceof FunctionalTestCase ) ) {
super.runTest( test, testResult );
}
else {
FunctionalTestCase functionalTest = ( ( FunctionalTestCase ) test );
try {
// disallow rebuilding the schema because this is the last test
// in this suite, thus it is about to get dropped immediately
// afterwards anyway...
environment.setAllowRebuild( testPosition < testCount );
functionalTest.setEnvironment( environment );
super.runTest( functionalTest, testResult );
}
finally {
functionalTest.setEnvironment( null );
}
}
}
SjsxpReaderTest.java 文件源码
项目:xstream
阅读 34
收藏 0
点赞 0
评论 0
public static Test suite() {
try {
Class.forName(className);
return new TestSuite(SjsxpReaderTest.class);
} catch (ClassNotFoundException e) {
return new TestCase(SjsxpReaderTest.class.getName() + ": not available") {
public int countTestCases() {
return 1;
}
public void run(TestResult result) {
}
};
}
}
SjsxpWriterTest.java 文件源码
项目:xstream
阅读 30
收藏 0
点赞 0
评论 0
public static Test suite() {
try {
Class.forName(className);
return new TestSuite(SjsxpWriterTest.class);
} catch (ClassNotFoundException e) {
return new TestCase(SjsxpWriterTest.class.getName() + ": not available") {
public int countTestCases() {
return 1;
}
public void run(TestResult result) {
}
};
}
}
CacheHitTest.java 文件源码
项目:mondrian
阅读 41
收藏 0
点赞 0
评论 0
/**
* Loops <code>n</code> times, each time run a random test case
* in the test <code>suite</code>
*
* @param suite the suite of test cases
* @param n number of times
* @throws Exception on error
*/
public void runRandomSuite(TestSuite suite, int n)
throws Exception
{
final TestResult tres = new TestResult();
final MondrianServer server =
MondrianServer.forConnection(getTestContext().getConnection());
for (int i = 0; i < n; i++) {
int suiteIdx = (int) (Math.random() * suite.testCount());
TestSuite test = (TestSuite) suite.testAt(suiteIdx);
int testIdx = (int) (Math.random() * test.testCount());
test.testAt(testIdx).run(tres);
}
report(server.getMonitor().getServer());
}
CacheHitTest.java 文件源码
项目:mondrian
阅读 43
收藏 0
点赞 0
评论 0
/**
* Loops <code>numIte</code> times, each time run all child test
* suite in the <code>suite</code>
*
* @param suite the suite of test suites
* @param numIter number of iterations
* @throws Exception on error
*/
public void runTestSuiteInOrder(TestSuite suite, int numIter)
throws Exception
{
final TestResult tres = new TestResult();
final MondrianServer server =
MondrianServer.forConnection(getTestContext().getConnection());
for (int i = 0; i < numIter; i++) {
TestSuite test = (TestSuite) suite.testAt(i % suite.testCount());
for (int j = 0; j < test.testCount(); j++) {
test.testAt(j).run(tres);
}
}
report(server.getMonitor().getServer());
}
CoreTestRunner.java 文件源码
项目:In-the-Box-Fork
阅读 29
收藏 0
点赞 0
评论 0
@Override
public TestResult doRun(Test suite, boolean wait) {
setPrinter(createPrinter());
/*
* Make sure the original suite is unreachable after we have
* created the new one, so GC can dispose terminated tests.
*/
CoreTestSuite coreTestSuite = new CoreTestSuite(suite, fFlags, fStep, null);
XmlReportPrinter xmlReportPrinter = xmlReportsDirectory != null
? new XmlReportPrinter(coreTestSuite)
: null;
TestResult result = super.doRun(coreTestSuite, wait);
if (xmlReportPrinter != null) {
System.out.print("Printing XML Reports... ");
xmlReportPrinter.setResults(result);
int numFiles = xmlReportPrinter.generateReports(xmlReportsDirectory);
System.out.println(numFiles + " files written.");
}
return result;
}
ActiveTestSuite.java 文件源码
项目:lcm
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void runTest(final Test test, final TestResult result) {
Thread t = new Thread() {
@Override
public void run() {
try {
// inlined due to limitation in VA/Java
//ActiveTestSuite.super.runTest(test, result);
test.run(result);
} finally {
ActiveTestSuite.this.runFinished();
}
}
};
t.start();
}