本文整理汇总了Java中org.junit.runner.JUnitCore类的典型用法代码示例。如果您正苦于以下问题:Java JUnitCore类的具体用法?Java JUnitCore怎么用?Java JUnitCore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JUnitCore类属于org.junit.runner包,在下文中一共展示了JUnitCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.junit.runner.JUnitCore; //导入依赖的package包/类
public static void main(String[] args) {
final Result result =
JUnitCore.runClasses(
codeu.chat.common.SecretTest.class,
codeu.chat.relay.ServerTest.class,
codeu.chat.server.BasicControllerTest.class,
codeu.chat.server.RawControllerTest.class,
codeu.chat.util.TimeTest.class,
codeu.chat.util.TokenizerTest.class,
codeu.chat.util.UuidTest.class,
codeu.chat.util.store.StoreTest.class
);
for (final Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
示例2: runTestSuiteAgainst
import org.junit.runner.JUnitCore; //导入依赖的package包/类
/**
* Creates and runs a JUnit test runner for testSuite.
*
* @param testSuite the class defining test cases to run
* @param view a UI component to report test failures to
* @return the counts of failures and total test cases.
*/
static RunResult runTestSuiteAgainst(Class testSuite, View view)
{
if(testSuite == null)
throw new NullPointerException("testSuite");
if(view == null)
throw new NullPointerException("view");
Result result = new JUnitCore().run(testSuite);
if (result.getFailureCount() > 0)
{
for (Failure f : result.getFailures())
view.declarePassProgramTestFailure(f.getTrace());
}
return new RunResult(result.getFailureCount(), result.getRunCount());
}
示例3: main
import org.junit.runner.JUnitCore; //导入依赖的package包/类
public static void main(String[] args) {
final Result result =
JUnitCore.runClasses(
codeu.chat.common.SecretTest.class,
codeu.chat.relay.ServerTest.class,
codeu.chat.server.BasicControllerTest.class,
codeu.chat.server.RawControllerTest.class,
codeu.chat.util.TimeTest.class,
codeu.chat.util.UuidTest.class,
codeu.chat.util.store.StoreTest.class
);
for (final Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
示例4: main
import org.junit.runner.JUnitCore; //导入依赖的package包/类
/**
* .
* @param args .
* @throws ClassNotFoundException .
*/
public static void main(String... args) throws ClassNotFoundException {
int retCode = 0;
String resultMessage = "SUCCESS";
String[] classAndMethod = args[0].split("#");
Request request = Request.method(Class.forName(classAndMethod[0]),
classAndMethod[1]);
Result result = new JUnitCore().run(request);
if (!result.wasSuccessful()) {
retCode = 1;
resultMessage = "FAILURE";
}
System.out.println(resultMessage);
System.exit(retCode);
}
示例5: executarTodosOs50Testes
import org.junit.runner.JUnitCore; //导入依赖的package包/类
/**
* Chama o motor de testes JUnit.
*/
private static void executarTodosOs50Testes()
{
final Result result = JUnitCore.runClasses( GrafoTest.class );
final StringBuilder mensagem = new StringBuilder();
if( result.getFailureCount() > 0 )
{
mensagem.append( "############## OS SEGUINTES TESTES FALHARAM!! "
+ "#####################################\n" );
} else
{
mensagem.append( "############## TODOS OS TESTES FORAM EXECUTADOS "
+ "COM SUCESSO!! #######################\n" );
}
for( final Failure failure: result.getFailures() )
{
mensagem.append( failure.getDescription() ).append( '\n' );
mensagem.append( failure.getMessage() ).append( '\n' );
}
System.out.println( mensagem );
}
示例6: runTestsAndAssertCounters
import org.junit.runner.JUnitCore; //导入依赖的package包/类
/**
* Run the tests in the supplied {@code testClass}, using the specified
* {@link Runner}, and assert the expectations of the test execution.
*
* <p>If the specified {@code runnerClass} is {@code null}, the tests
* will be run with the runner that the test class is configured with
* (i.e., via {@link RunWith @RunWith}) or the default JUnit runner.
*
* @param runnerClass the explicit runner class to use or {@code null}
* if the implicit runner should be used
* @param testClass the test class to run with JUnit
* @param expectedStartedCount the expected number of tests that started
* @param expectedFailedCount the expected number of tests that failed
* @param expectedFinishedCount the expected number of tests that finished
* @param expectedIgnoredCount the expected number of tests that were ignored
* @param expectedAssumptionFailedCount the expected number of tests that
* resulted in a failed assumption
*/
public static void runTestsAndAssertCounters(Class<? extends Runner> runnerClass, Class<?> testClass,
int expectedStartedCount, int expectedFailedCount, int expectedFinishedCount, int expectedIgnoredCount,
int expectedAssumptionFailedCount) throws Exception {
TrackingRunListener listener = new TrackingRunListener();
if (runnerClass != null) {
Constructor<?> constructor = runnerClass.getConstructor(Class.class);
Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass);
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
else {
JUnitCore junit = new JUnitCore();
junit.addListener(listener);
junit.run(testClass);
}
assertEquals("tests started for [" + testClass + "]:", expectedStartedCount, listener.getTestStartedCount());
assertEquals("tests failed for [" + testClass + "]:", expectedFailedCount, listener.getTestFailureCount());
assertEquals("tests finished for [" + testClass + "]:", expectedFinishedCount, listener.getTestFinishedCount());
assertEquals("tests ignored for [" + testClass + "]:", expectedIgnoredCount, listener.getTestIgnoredCount());
assertEquals("failed assumptions for [" + testClass + "]:", expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount());
}
示例7: runTestAndVerifyHierarchies
import org.junit.runner.JUnitCore; //导入依赖的package包/类
private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive,
boolean isBarContextActive, boolean isBazContextActive) {
JUnitCore jUnitCore = new JUnitCore();
Result result = jUnitCore.run(testClass);
assertTrue("all tests passed", result.wasSuccessful());
assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());
ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));
ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
assertThat(barContext, notNullValue());
assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));
ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
assertThat(fooContext, notNullValue());
assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
}
示例8: runTaskCase
import org.junit.runner.JUnitCore; //导入依赖的package包/类
@Override
public void runTaskCase() throws Exception {
AbstractCaseData.setCaseData(null);
String caseDataInfo = this.tcr.getTaskCase().getCaseDataInfo();
if (!caseDataInfo.isEmpty()) {
CaseData caseData = AbstractCaseData.getCaseData(caseDataInfo);
LOG.debug("Injecting case data: {} = {}", caseDataInfo, caseData.getValue());
AbstractCaseData.setCaseData(caseData);
}
TaskCase tc = this.tcr.getTaskCase();
LOG.debug("Loading case {}", tc.format());
CaseRunListener trl = new CaseRunListener(this.db, this.tcr);
JUnitCore core = new JUnitCore();
core.addListener(trl);
core.run(Request.method(Class.forName(tc.getCaseClass()), tc.getCaseMethod()));
}
示例9: run
import org.junit.runner.JUnitCore; //导入依赖的package包/类
@Test
public void run() {
JUnitCore junitCore = new JUnitCore();
Result result = junitCore.run(TestDummy.class);
List<Failure>failures = result.getFailures();
if(!(failures == null || failures.isEmpty())) {
for(Failure f : failures) {
System.out.println(f.getMessage());
}
}
Assert.assertEquals(2, result.getRunCount());
Assert.assertEquals(0, result.getIgnoreCount());
Assert.assertEquals(0, result.getFailureCount());
Assert.assertEquals("After was not executed", "true", System.getProperty("JUnit_After"));
Assert.assertEquals("AfterClass was not executed", "true", System.getProperty("JUnit_AfterClass"));
}
示例10: start
import org.junit.runner.JUnitCore; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
AppLauncher.getInstance().setRemoteStage(stage);
new Thread(new Runnable() {
public void run() {
try {
System.out.println("Running junit");
Result r = new JUnitCore().run(Request.method(Class.forName(className), testName));
System.out.println("got result = " + r.wasSuccessful());
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
} finally {
//System.exit(0);
}
}
}).start();
}
示例11: runTests
import org.junit.runner.JUnitCore; //导入依赖的package包/类
private static void runTests(){
JUnitCore junit = new JUnitCore();
Result result = junit.run(Tests.class);
System.err.println("Ran " + result.getRunCount() + " tests in "+ result.getRunTime() +"ms.");
if (result.wasSuccessful()) System.out.println("All tests were successfull!");
else {
System.err.println(result.getFailureCount() + "Failures:");
for (Failure fail: result.getFailures()){
System.err.println("Failure in: "+ fail.getTestHeader());
System.err.println(fail.getMessage());
System.err.println(fail.getTrace());
System.err.println();
}
}
}
示例12: main
import org.junit.runner.JUnitCore; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Need an argument for target directory: i.e. /var/tmp/silverking_holstben/skfs/skfs_mnt/skfs");
return;
}
targetDirPath = args[0];
absTestsDir = targetDirPath + sep + testsDirName;
targetDir = new File(targetDirPath);
testsDir = new File(targetDirPath, testsDirName);
parentFile = new File(absTestsDir, parentFileName);
parentFileRename = new File(absTestsDir, parentFileName+"Rename");
Result result = JUnitCore.runClasses(SkfsRenameGlenn.class);
printSummary(result);
}
示例13: main
import org.junit.runner.JUnitCore; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Need an argument for target directory: i.e. /var/tmp/silverking_holstben/skfs/skfs_mnt/skfs");
return;
}
targetDirPath = args[0];
absTestsDir = targetDirPath + sep + testsDirName;
targetDir = new File(targetDirPath);
testsDir = new File(targetDirPath, testsDirName);
parentDir = new File(absTestsDir, parentDirName);
Result result = JUnitCore.runClasses(SkfsCopyGlenn.class);
printSummary(result);
System.out.println("exists: " + exists);
}
示例14: testTextResultPresentation
import org.junit.runner.JUnitCore; //导入依赖的package包/类
@Test
public void testTextResultPresentation() throws Exception {
IResultPresentation presentation = new TextResultPresentation();
final String genericExpected = "" + "Testcase: junit.framework.TestCase.test()" + NEW_LINE
+ "Mutated method: java.lang.Object.hashCode()" + NEW_LINE + "Return value generator: "
+ SAMPLE_RET_VAL_GEN_NAME + NEW_LINE + "Result: %s" + NEW_LINE + ".";
String output;
String expected;
Result result;
result = new Result();
output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
expected = String.format(genericExpected, "OK");
assertEquals(expected, output);
result = new JUnitCore().run(Request.method(SampleJUnitTestClass.class, "b"));
output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
expected = String.format(genericExpected, "1 of 1 FAILED" + NEW_LINE + "Exception: java.lang.AssertionError");
assertEquals(expected, output);
}
示例15: testDatabaseResultPresentation
import org.junit.runner.JUnitCore; //导入依赖的package包/类
@Test
public void testDatabaseResultPresentation() {
IResultPresentation presentation = new DatabaseResultPresentation();
presentation.setExecutionId(ExecutionIdFactory.parseShortExecutionId("EXEC"));
final String genericExpected = "INSERT INTO Test_Result_Import (execution, testcase, method, retValGen, killed, assertErr, exception) VALUES ('EXEC', 'junit.framework.TestCase.test()', 'java.lang.Object.hashCode()', '%s', %s, %s, '%s');";
String output;
String expected;
Result result;
result = new Result();
output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
expected = String.format(genericExpected, SAMPLE_RET_VAL_GEN_NAME, false, false, "");
assertEquals(expected, output);
result = new JUnitCore().run(Request.method(SampleJUnitTestClass.class, "b"));
output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
expected = String.format(genericExpected, SAMPLE_RET_VAL_GEN_NAME, true, true, AssertionError.class.getName());
assertEquals(expected, output);
}