Java Code Examples for junit.framework.TestResult#startTest()

The following examples show how to use junit.framework.TestResult#startTest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Benchmark.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 2
Source File: FunctionalTestClassTestSuite.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 );
		}
	}
}
 
Example 3
Source File: ExpandFolderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
    result.startTest(this);
    StringBuffer times = new StringBuffer("\n");
    AtomicLong min = new AtomicLong(Long.MAX_VALUE);
    AtomicLong max = new AtomicLong(Long.MIN_VALUE);
    iterateTests(result, times, suite, min, max);
    
    System.err.println(times.toString());
    
    if (max.longValue() > 3 * min.longValue()) {
        result.addFailure(this, new AssertionFailedError(times.toString()));
    }
    result.endTest(this);
}
 
Example 4
Source File: TimeOutTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run(TestResult result) {
    if (!canRun()) {
        return;
    }
    this.main = Thread.currentThread();
    
    TestResult mine = new TestResult();
    result.startTest(this);
    super.run(mine);
    
    if (mine.errorCount() != 0) {
        Enumeration en = mine.errors();
        while(en.hasMoreElements()) {
            TestFailure f = (TestFailure)en.nextElement();
            result.addError(this, f.thrownException());
        }
        return;
    }
    if (expectedResult != (mine.failureCount() == 0)) {
        result.addFailure(this, 
            new AssertionFailedError(
                "expectedResult: " + expectedResult + "failureCount: " + mine.failureCount() + " for " + getName()
            )
        );
        return;
    }
    
    result.endTest(this);
}
 
Example 5
Source File: LinearSpeedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Test suite() {
    System.setProperty("ignore.random.failures", "false");
    final Test t = NbTestSuite.linearSpeedSuite(LinearSpeedTest.class, 2,2);

    class ThisHasToFail extends TestCase {
        
        public int countTestCases() {
            return 1;
        }

        public String getName() {
            return "LinearSpeedTest";
        }

        public void run(TestResult testResult) {
            TestResult r = new TestResult();
            t.run(r);
            
            int count = r.errorCount() + r.failureCount();
            if (count == 0) {
                testResult.startTest(this);
                testResult.addFailure(this, new AssertionFailedError("LinearSpeedTest must fail: " + count));
                testResult.endTest(this);
            } else {
                testResult.startTest(this);
                testResult.endTest(this);
            }
        }
    }
    return new ThisHasToFail();
}
 
Example 6
Source File: ServiceTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
    result.startTest(this);

    try {

        Map<String, Object> serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("test", this, "testResult", result));

        // do something with the errorMessage
        String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
        if (UtilValidate.isNotEmpty(errorMessage)) {
            result.addFailure(this, new AssertionFailedError(errorMessage));
        }

        // do something with the errorMessageList
        List<Object> errorMessageList = UtilGenerics.checkList(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
        if (UtilValidate.isNotEmpty(errorMessageList)) {
            for (Object message: errorMessageList) {
                result.addFailure(this, new AssertionFailedError(message.toString()));
            }
        }

        // do something with the errorMessageMap
        Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
        if (!UtilValidate.isEmpty(errorMessageMap)) {
            for (Map.Entry<String, Object> entry: errorMessageMap.entrySet()) {
                result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
            }
        }

    } catch (GenericServiceException e) {
        result.addError(this, e);
    }

    result.endTest(this);
}
 
Example 7
Source File: EntityXmlAssertTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
    result.startTest(this);

    try {
        URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
        List<Object> errorMessages = new LinkedList<Object>();

        if ("assert".equals(this.action)) {
            EntityDataAssert.assertData(entityXmlURL, delegator, errorMessages);
        } else if ("load".equals(this.action)) {
            EntitySaxReader reader = new EntitySaxReader(delegator);
            reader.parse(entityXmlURL);
        } else {
            // uh oh, bad value
            result.addFailure(this, new AssertionFailedError("Bad value [" + this.action + "] for action attribute of entity-xml element"));
        }

        if (UtilValidate.isNotEmpty(errorMessages)) {
            for (Object failureMessage: errorMessages) {
                result.addFailure(this, new AssertionFailedError(failureMessage.toString()));
            }
        }
    } catch (Exception e) {
        result.addError(this, e);
    }

    result.endTest(this);
}
 
Example 8
Source File: RawTestImpl.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest(this, testLocation);
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
Example 9
Source File: MatcherTestImpl.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest();
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
Example 10
Source File: TestImplementorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void run(TestResult result) {
	result.startTest(this);
	Protectable p= new Protectable() {
		public void protect() throws Throwable {
			fTestCase.runBare();
			fTestCase.runBare();
		}
	};
	result.runProtected(this, p);
	result.endTest(this);
}
 
Example 11
Source File: ScriptTestAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void run(TestResult result) {
    try {
        result.startTest(this);

        // let's run the script
        InvokerHelper.runScript(scriptClass, arguments);
        result.endTest(this);
    } catch (Exception e) {
        result.addError(this, e);
    }
}
 
Example 12
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult testResult) {
  testResult.startTest(this);
  try {
    fail("broken");
  } finally {
    testResult.endTest(this);
  }
}
 
Example 13
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult testResult) {
  testResult.startTest(this);
  testResult.runProtected(
      this,
      new Protectable() {
        @Override
        public void protect() throws Throwable {
          fail("broken");
        }
      });
  testResult.endTest(this);
}
 
Example 14
Source File: NumberedTestCase.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected void run(final TestResult result, final Method testMethod) {
    final Test test = createTest(testMethod);
    result.startTest(test);
    final Protectable p = new Protectable() {
        public void protect() throws Throwable {
            runTestMethod(testMethod);
        }
    };
    //System.out.println(">>" + NumberedTestCase.class.getName() + "> started: " + testMethod.toGenericString());
    result.runProtected(test, p);
    result.endTest(test);
    //System.out.println(">>" + NumberedTestCase.class.getName() + "> done: " + testMethod.toGenericString());
}