org.junit.runner.Request#method()源码实例Demo

下面列出了org.junit.runner.Request#method() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: io   文件: SingleJUnitTestRunner.java
/**
 * .
 * @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);
}
 
源代码2 项目: The-Kraken-Pathfinding   文件: JUnit_Test.java
/**
 * Lanceur d'une seule méthode de test
 * 
 * @param args
 * @throws ClassNotFoundException
 */
public static void main(String[] args) throws ClassNotFoundException
{
	if(args.length != 2)
	{
		System.out.println("Usage : JUnit_Test class method");
	}
	else
	{
		Request request = Request.method(Class.forName(args[0]), args[1]);

		Result result = new JUnitCore().run(request);
		System.exit(result.wasSuccessful() ? 0 : 1);
	}
}
 
源代码3 项目: JQF   文件: GuidedFuzzing.java
/**
 * Runs the guided fuzzing loop for a resolved class.
 *
 * <p>The test class must be annotated with <tt>@RunWith(JQF.class)</tt>
 * and the test method must be annotated with <tt>@Fuzz</tt>.</p>
 *
 * <p>Once this method is invoked, the guided fuzzing loop runs continuously
 * until the guidance instance decides to stop by returning <tt>false</tt>
 * for {@link Guidance#hasInput()}. Until the fuzzing stops, this method
 * cannot be invoked again (i.e. at most one guided fuzzing can be running
 * at any time in a single JVM instance).</p>
 *
 * @param testClass     the test class containing the test method
 * @param testMethod    the test method to execute in the fuzzing loop
 * @param guidance      the fuzzing guidance
 * @param out           an output stream to log Junit messages
 * @throws IllegalStateException if a guided fuzzing run is currently executing
 * @return the Junit-style test result
 */
public synchronized static Result run(Class<?> testClass, String testMethod,
                                      Guidance guidance, PrintStream out) throws IllegalStateException {

    // Ensure that the class uses the right test runner
    RunWith annotation = testClass.getAnnotation(RunWith.class);
    if (annotation == null || !annotation.value().equals(JQF.class)) {
        throw new IllegalArgumentException(testClass.getName() + " is not annotated with @RunWith(JQF.class)");
    }


    // Set the static guided instance
    setGuidance(guidance);

    // Register callback
    SingleSnoop.setCallbackGenerator(guidance::generateCallBack);

    // Create a JUnit Request
    Request testRequest = Request.method(testClass, testMethod);

    // Instantiate a runner (may return an error)
    Runner testRunner = testRequest.getRunner();

    // Start tracing for the test method
    SingleSnoop.startSnooping(testClass.getName() + "#" + testMethod);

    // Run the test and make sure to de-register the guidance before returning
    try {
        JUnitCore junit = new JUnitCore();
        if (out != null) {
            junit.addListener(new TextListener(out));
        }
        return junit.run(testRunner);
    } finally {
        unsetGuidance();
    }



}
 
源代码4 项目: SimFix   文件: JUnitRunner.java
/**
 * args[0] test class
 * args[1] test method (optional)
 * 
 * @param args
 */
public static void main(String[] args) {

  if (args.length < 1 || args.length > 2) {
    System.err.println("Usage: java -cp .:JUnitRunner-0.0.1-SNAPSHOT.jar:<project cp> uk.ac.shef.JUnitRunner <full test class name> [test method name]");
    System.exit(-1);
  }

  Class<?> clazz = null;
  try {
    clazz = Class.forName(args[0], false, JUnitRunner.class.getClassLoader());
  } catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.exit(-1);
  }

  Request request = null;
  if (args.length == 1) {
    request = Request.aClass(clazz);
  } else if (args.length == 2) {
    request = Request.method(clazz, args[1]);
  }

  JUnitListener listener = new JUnitListener();

  JUnitCore runner = new JUnitCore();
  runner.addListener(listener);
  runner.run(request); // run test method

  System.exit(0);
}
 
源代码5 项目: nopol   文件: MethodTestRunner.java
private static void runTest(String test) {
    try {
        String[] classAndMethod = test.split("#");
        System.out.println(test);
        Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]);
        JUnitCore junit = new JUnitCore();
        junit.addListener(new TextListener(System.out));
        junit.run(request);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
 
源代码6 项目: nopol   文件: JUnitSingleTestRunner.java
@Override
public Result call() throws Exception {
    JUnitCore runner = new JUnitCore();
    runner.addListener(listener);
    Request request = Request.method(testClassFromCustomClassLoader(), testCaseName());
    try {
        return runner.run(request);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
源代码7 项目: nopol   文件: JUnitSingleTestResultRunner.java
@Override
public Result call() throws Exception {
	JUnitCore runner = new JUnitCore();
	runner.addListener(listener);
	Request request = Request.method(testClassFromCustomClassLoader(), testCaseName());
	return runner.run(request);
}
 
源代码8 项目: nopol   文件: DynamicClassCompilerTest.java
@Test
public void accessPublicMethodFromDifferentClassloader() throws ClassNotFoundException {
	String qualifiedName = "test.dynamic.compiler.HelloWorld";
	String qualifiedTestName = "test.dynamic.compiler.HelloWorldTest";
	String code = 
			"package test.dynamic.compiler;" +
			"public class HelloWorld {" +
			"	@Override" +
			"	public String toString() {" +
			"		return \"Hello World!\";" +
			"	}" + 
			"}";
	String testCode = 
			"package test.dynamic.compiler;" +
			"import org.junit.Test;" +
			"import static org.junit.Assert.assertEquals;" +
			"public class HelloWorldTest {" +
			"	@Test" +
			"	public void toStringTest() {" +
			"		assertEquals(\"Hello World!\", new HelloWorld().toString());" +
			"	}" + 
			"}";
	ClassLoader parentLoader = BytecodeClassLoaderBuilder.loaderFor(qualifiedName, code);
	Map<String, String> sources = adHocMap(asList(qualifiedName, qualifiedTestName), asList(code, testCode));
	ClassLoader loader = BytecodeClassLoaderBuilder.loaderFor(sources, parentLoader);
	Class<?> testClass = loader.loadClass(qualifiedTestName);
	Class<?> theClass = loader.loadClass(qualifiedName);
	assertFalse(parentLoader == loader);
	assertTrue(loader == theClass.getClassLoader());
	assertTrue(loader == testClass.getClassLoader());
	JUnitCore junit = new JUnitCore();
	Request request = Request.method(testClass, "toStringTest");
	Result result = junit.run(request);
	assertTrue(result.wasSuccessful());
}
 
源代码9 项目: nopol   文件: DynamicClassCompilerTest.java
@Test
public void accessProtectedMethodFromSameClassloaderAndPackage() throws ClassNotFoundException {
	String qualifiedName = "test.dynamic.compiler.HelloWorld";
	String qualifiedTestName = "test.dynamic.compiler.HelloWorldTest";
	String code = 
			"package test.dynamic.compiler;" +
			"public class HelloWorld {" +
			"	protected String message() {" +
			"		return \"Hello World!\";" +
			"	}" + 
			"}";
	String testCode = 
			"package test.dynamic.compiler;" +
			"import org.junit.Test;" +
			"import static org.junit.Assert.assertEquals;" +
			"public class HelloWorldTest {" +
			"	@Test" +
			"	public void protectedMethodTest() {" +
			"		assertEquals(\"Hello World!\", new HelloWorld().message());" +
			"	}" + 
			"}";
	Map<String, String> sources = adHocMap(asList(qualifiedName, qualifiedTestName), asList(code, testCode));
	ClassLoader loader = BytecodeClassLoaderBuilder.loaderFor(sources);
	Class<?> testClass = loader.loadClass(qualifiedTestName);
	Class<?> theClass = loader.loadClass(qualifiedName);
	assertTrue(loader == theClass.getClassLoader());
	assertTrue(loader == testClass.getClassLoader());
	JUnitCore junit = new JUnitCore();
	Request request = Request.method(testClass, "protectedMethodTest");
	Result result = junit.run(request);
	assertTrue(result.wasSuccessful());
}
 
源代码10 项目: nopol   文件: DynamicClassCompilerTest.java
@Test
public void accessProtectedMethodFromDifferentClassloaderButSamePackageName() throws ClassNotFoundException {
	String qualifiedName = "test.dynamic.compiler.HelloWorld";
	String qualifiedTestName = "test.dynamic.compiler.HelloWorldTest";
	String code = 
			"package test.dynamic.compiler;" +
			"public class HelloWorld {" +
			"	protected String message() {" +
			"		return \"Hello World!\";" +
			"	}" + 
			"}";
	String testCode = 
			"package test.dynamic.compiler;" +
			"import org.junit.Test;" +
			"import static org.junit.Assert.assertEquals;" +
			"public class HelloWorldTest {" +
			"	@Test" +
			"	public void protectedMethodTest() {" +
			"		assertEquals(\"Hello World!\", new HelloWorld().message());" +
			"	}" + 
			"}";
	Map<String, String> sources = adHocMap(asList(qualifiedName, qualifiedTestName), asList(code, testCode));
	ClassLoader parentLoader = BytecodeClassLoaderBuilder.loaderFor(qualifiedName, code);
	ClassLoader loader = BytecodeClassLoaderBuilder.loaderFor(sources, parentLoader);
	Class<?> testClass = loader.loadClass(qualifiedTestName);
	Class<?> theClass = loader.loadClass(qualifiedName);
	assertFalse(parentLoader == loader);
	assertTrue(loader == theClass.getClassLoader());
	assertTrue(loader == testClass.getClassLoader());
	JUnitCore junit = new JUnitCore();
	Request request = Request.method(testClass, "protectedMethodTest");
	Result result = junit.run(request);
	assertTrue(result.wasSuccessful());
}
 
源代码11 项目: spoon-examples   文件: TestRunner.java
public static List<Failure> runTest(String fullQualifiedName, String testCaseName, String[] classpath) throws MalformedURLException, ClassNotFoundException {
    ClassLoader classLoader = new URLClassLoader(
            arrayStringToArrayUrl.apply(classpath),
            ClassLoader.getSystemClassLoader()
    );
    Request request = Request.method(classLoader.loadClass(fullQualifiedName), testCaseName);
    Runner runner = request.getRunner();
    RunNotifier fNotifier = new RunNotifier();
    final TestListener listener = new TestListener();
    fNotifier.addFirstListener(listener);
    fNotifier.fireTestRunStarted(runner.getDescription());
    runner.run(fNotifier);
    return listener.getTestFails();
}
 
源代码12 项目: astor   文件: JUnitSingleTestRunner.java
@Override
public Result call() throws Exception {
    JUnitCore runner = new JUnitCore();
    runner.addListener(listener);
    Request request = Request.method(testClassFromCustomClassLoader(), testCaseName());
    try {
        return runner.run(request);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
源代码13 项目: astor   文件: JUnitSingleTestResultRunner.java
@Override
public Result call() throws Exception {
	JUnitCore runner = new JUnitCore();
	runner.addListener(listener);
	Request request = Request.method(testClassFromCustomClassLoader(), testCaseName());
	return runner.run(request);
}
 
源代码14 项目: astor   文件: MethodTestRunner.java
private static void runTest(String test) {
	try {
		String[] classAndMethod = test.split("#");
		System.out.println(test);
		Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]);
		JUnitCore junit = new JUnitCore();
		junit.addListener(new TextListener(System.out));
		junit.run(request);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
}
 
源代码15 项目: at.info-knowledge-base   文件: TestRunner.java
@Test
public void test() {
    Request request = Request.method(testMethod.getDeclaringClass(), testMethod.getName());
    Result result = new JUnitCore().run(request);
    if (result.getIgnoreCount() > 0)
        throw new AssumptionViolatedException("Test " + testMethod.getDeclaringClass()
                + "." + testMethod.getName() + " were ignored");
    if (result.getFailureCount() > 0) {
        Assert.fail(result.getFailures().toString());
    }
}
 
源代码16 项目: s3mper   文件: TestCaseRunner.java
public static void main(String[] args) throws ClassNotFoundException {
    Request testCase = Request.method(Class.forName(args[0]), args[1]);
    
    JUnitCore core = new JUnitCore();
    
    Result result = core.run(testCase);
    
    for(Failure f: result.getFailures()) {
        System.out.println(f.getMessage());
        f.getException().printStackTrace();
    }
    System.exit(result.wasSuccessful() ? 0 : 1);
}
 
源代码17 项目: quickperf   文件: JUnit4TestRunner.java
@Override
public TestIssue executeTestMethod(Class<?> testClass, String methodName) {

    Request junitRequestOfMethod = Request.method(testClass, methodName);

    Result testResult = new JUnitCore().run(junitRequestOfMethod);

    List<Failure> jUnit4Failures = testResult.getFailures();

    List<Throwable> jUnit4failuresAsThrowables = convertJUnit4FailuresToThrowables(jUnit4Failures);

    return  TestIssue.buildInNewJvmFrom(jUnit4failuresAsThrowables);

}