本文整理匯總了Java中org.junit.runners.Suite類的典型用法代碼示例。如果您正苦於以下問題:Java Suite類的具體用法?Java Suite怎麽用?Java Suite使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Suite類屬於org.junit.runners包,在下文中一共展示了Suite類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRunFinished
import org.junit.runners.Suite; //導入依賴的package包/類
@Override
public void testRunFinished(Result result) throws Exception {
super.testRunFinished(result);
JCodeModel codeModel = new JCodeModel();
JDefinedClass resultClass = codeModel._class(getSuiteClassName());
JClass suiteClazz = codeModel.ref(Suite.class);
resultClass.annotate(RunWith.class).param(VALUE_PARAM, suiteClazz);
JClass suiteClasses = codeModel.ref(Suite.SuiteClasses.class);
JAnnotationArrayMember testClassArray = resultClass.annotate(suiteClasses).paramArray(VALUE_PARAM);
testClassesAndTheirTests.keySet().forEach(className -> addClassToSuite(codeModel, testClassArray, className));
resultClass.javadoc().add(getJavaDocComment());
File file = new File(getTargetDirectory());
if ( !file.exists() && !file.mkdirs() ) {
throw new RuntimeException("Cannot create folder " + file.getAbsolutePath());
}
codeModel.build(file);
}
示例2: isTestClass
import org.junit.runners.Suite; //導入依賴的package包/類
private boolean isTestClass(Class<?> c) {
if (Modifier.isAbstract(c.getModifiers())) {
return false;
}
if (c.getAnnotation(Suite.SuiteClasses.class) != null) {
return true;
}
for (Method met : c.getMethods()) {
if (met.getAnnotation(Test.class) != null) {
return true;
}
}
return false;
}
示例3: isJUnit4TestClass
import org.junit.runners.Suite; //導入依賴的package包/類
/**
* @return true if {@param cls} is {@link JUnit4} annotated.
*/
protected boolean isJUnit4TestClass(Class cls) {
// Need to find test classes, otherwise crashes with b/11790448.
if (!cls.getName().endsWith("Test")) {
return false;
}
// Check the annotations.
Annotation annotation = cls.getAnnotation(RunWith.class);
if (annotation != null) {
RunWith runWith = (RunWith) annotation;
Object value = runWith.value();
if (value.equals(JUnit4.class) || value.equals(Suite.class)) {
return true;
}
}
return false;
}
示例4: assertTestRunner
import org.junit.runners.Suite; //導入依賴的package包/類
@SuppressWarnings({"rawtypes", "LoopStatementThatDoesntLoop"})
private boolean assertTestRunner(String testClass) {
try {
RunWith runWith = Class.forName(testClass).getAnnotation(RunWith.class);
if (runWith == null) {
throw new RuntimeException("Missing [@" + RunWith.class.getCanonicalName() + "(" + TestRunner.class.getCanonicalName()
+ ".class)] on class [" + testClass + "]");
}
if (runWith.value().equals(Suite.class)) {
SuiteClasses suiteClasses = Class.forName(testClass).getAnnotation(SuiteClasses.class);
for (Class suiteTestClass : suiteClasses.value()) {
return assertTestRunner(suiteTestClass.getCanonicalName());
}
} else if (!runWith.value().equals(TestRunner.class)) {
throw new RuntimeException("Unsupported run with [" + runWith.value().getCanonicalName() + "] on class [" + testClass + "]");
}
} catch (Exception exception) {
String message = "The test [" + testClass + "] included a rule [" + getClass().getCanonicalName() + "] but did not include a [@"
+ RunWith.class.getCanonicalName() + "(" + TestRunner.class.getCanonicalName() + ".class)] class annotation";
if (LOG.isErrorEnabled()) {
LOG.error(message, exception);
}
throw new RuntimeException(message, exception);
}
return true;
}
示例5: run
import org.junit.runners.Suite; //導入依賴的package包/類
public static void run(Configuration configuration, Class<?> clazz, String methodName) {
try {
Request request = null;
if (clazz!=null && methodName!=null) {
request = Request.method(clazz, methodName);
} else {
Suite suite = new Suite(new JUnit4Builder(), API_TEST_CLASSES);
request = Request.runner(suite);
}
Configuration originalConfiguration = WorkflowTest.cachedConfiguration;
WorkflowTest.cachedConfiguration = configuration;
JUnitCore junitCore = new JUnitCore();
Result result = junitCore.run(request);
WorkflowTest.cachedConfiguration = originalConfiguration;
checkResult(result);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: constructLeafRequest
import org.junit.runners.Suite; //導入依賴的package包/類
private Request constructLeafRequest(List<Description> leaves) {
final List<Runner> runners = new ArrayList<Runner>();
for (Description each : leaves) {
runners.add(buildRunner(each));
}
return new Request() {
@Override
public Runner getRunner() {
try {
return new Suite((Class<?>) null, runners) {
};
} catch (InitializationError e) {
return new ErrorReportingRunner(null, e);
}
}
};
}
示例7: buildRunner
import org.junit.runners.Suite; //導入依賴的package包/類
private Runner buildRunner(Description each) {
if (each.toString().equals("TestSuite with 0 tests")) {
return Suite.emptySuite();
}
if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) {
// This is cheating, because it runs the whole class
// to get the warning for this method, but we can't do better,
// because JUnit 3.8's
// thrown away which method the warning is for.
return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each)));
}
Class<?> type = each.getTestClass();
if (type == null) {
throw new RuntimeException("Can't locate a runner from description [" + each + "]");
}
String methodName = each.getMethodName();
if (methodName == null) {
return Request.aClass(type).getRunner();
}
return Request.method(type, methodName).getRunner();
}
示例8: buildRunner
import org.junit.runners.Suite; //導入依賴的package包/類
private Runner buildRunner(Description each) {
if (each.toString().equals("TestSuite with 0 tests")) {
return Suite.emptySuite();
}
if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) {
// This is cheating, because it runs the whole class
// to get the warning for this method, but we can't do better,
// because JUnit 3.8's
// thrown away which method the warning is for.
return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each)));
}
Class<?> type = each.getTestClass();
if (type == null) {
throw new RuntimeException("Can't build a runner from description [" + each + "]");
}
String methodName = each.getMethodName();
if (methodName == null) {
return Request.aClass(type).getRunner();
}
return Request.method(type, methodName).getRunner();
}
示例9: runTests
import org.junit.runners.Suite; //導入依賴的package包/類
private static Result runTests(Injector injector, Class<?>[] testClasses, Optional<Description> testFilter) throws InitializationError {
final JUnitCore junit = new JUnitCore();
junit.addListener(new JUnitRunListener(LOGGER));
final Request testRequest = Request.runner(new Suite(new GuiceInjectionJUnitRunner(injector), testClasses));
if (testFilter.isPresent()) {
return junit.run(testRequest.filterWith(testFilter.get()));
} else {
return junit.run(testRequest);
}
}
示例10: isTest
import org.junit.runners.Suite; //導入依賴的package包/類
/**
* Determine if this class contains JUnit tests
* @deprecated use {@code org.evosuite.junit.CoverageAnalysis.isTest(Class<?> cls)}
*
* @param className
* @return
*/
@Deprecated
public static boolean isTest(String className) {
// TODO-JRO Identifying tests should be done differently:
// If the class either contains methods
// annotated with @Test (> JUnit 4.0)
// or contains Test or Suite in it's inheritance structure
try {
Class<?> clazz = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(className);
Class<?> superClazz = clazz.getSuperclass();
while (!superClazz.equals(Object.class)) {
if (superClazz.equals(Suite.class))
return true;
if (superClazz.equals(Test.class))
return true;
superClazz = clazz.getSuperclass();
}
for (Method method : clazz.getMethods()) {
if (method.isAnnotationPresent(Test.class)) {
return true;
}
}
} catch (ClassNotFoundException e) {
logger.info("Could not load class: ", className);
}
return false;
}
示例11: addTests
import org.junit.runners.Suite; //導入依賴的package包/類
@Override
public void addTests(TestSuite suite) {
//$JUnit-BEGIN$
Suite.SuiteClasses suiteClasses = getClass().getAnnotation(Suite.SuiteClasses.class);
if (suiteClasses == null) {
Logger.getLogger(getClass()).warn("No @SuiteClasses annotation found");
return;
}
for (Class testClass : suiteClasses.value())
suite.addTest(new JUnit4TestAdapter(testClass));
//$JUnit-END$
}
示例12: getSuite
import org.junit.runners.Suite; //導入依賴的package包/類
/**
* Create a suite for {@code classes}, building Runners with {@code builder}.
* Throws an InitializationError if Runner construction fails
*/
public Runner getSuite(final RunnerBuilder builder,
Class<?>[] classes) throws InitializationError {
return new Suite(new RunnerBuilder() {
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
return getRunner(builder, testClass);
}
}, classes);
}
示例13: hasSuitableRunnner
import org.junit.runners.Suite; //導入依賴的package包/類
private boolean hasSuitableRunnner(final Class<?> clazz) {
final RunWith runWith = clazz.getAnnotation(RunWith.class);
if (runWith != null) {
return (runWith.value().equals(Suite.class));
}
return false;
}
示例14: convertClass
import org.junit.runners.Suite; //導入依賴的package包/類
/**
* @see junitconverter.stages.TestConversionStage#convertClass(junitconverter.testcase.TestCaseClass)
*/
public void convertClass(TestCaseClass testCase)
{
codeEditor.importClass(testCase, Suite.class);
codeEditor.importClass(testCase, RunWith.class);
codeEditor.importClass(testCase, SuiteClasses.class); // FIXME Doesn't import it properly. Adds a $ instead of . between SUite and SuiteClasses
}
示例15: isSuite
import org.junit.runners.Suite; //導入依賴的package包/類
private static boolean isSuite(Object child) {
return child instanceof Suite && !(child instanceof Parameterized) || child instanceof SuiteMethod;
}