本文整理匯總了Java中org.junit.runner.RunWith類的典型用法代碼示例。如果您正苦於以下問題:Java RunWith類的具體用法?Java RunWith怎麽用?Java RunWith使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RunWith類屬於org.junit.runner包,在下文中一共展示了RunWith類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildTypeSpec
import org.junit.runner.RunWith; //導入依賴的package包/類
private TypeSpec buildTypeSpec(List<MethodSpec> methodSpecs, List<FieldSpec> fieldSpecs, MethodSpec setUp) {
return TypeSpec.classBuilder(this.restControllerModel.getSimpleClassName())
.addAnnotation(Transactional.class)
.addAnnotation(
AnnotationSpec.builder(RunWith.class)
.addMember("value", "$T.class", SpringJUnit4ClassRunner.class)
.build()
)
.addAnnotation(
AnnotationSpec.builder(ComponentScan.class)
.addMember("basePackages", "{$S, $S}", "YOUR_DTOs_PACKAGE", "YOUR_SERVICEs_PACKAGE")
.build()
)
.addAnnotation(SpringBootTest.class)
.addModifiers(Modifier.PUBLIC)
.addFields(fieldSpecs)
.addMethod(setUp)
.addMethods(methodSpecs)
.build();
}
開發者ID:HomoEfficio,項目名稱:spring-web-api-test-stubber,代碼行數:22,代碼來源:SpringBootRestControllerTesterStubGenerator.java
示例2: testRunFinished
import org.junit.runner.RunWith; //導入依賴的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);
}
示例3: isJUnit4TestClass
import org.junit.runner.RunWith; //導入依賴的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: isJUnit4TestClass
import org.junit.runner.RunWith; //導入依賴的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;
if (runWith.value().equals(JUnit4.class)) {
return true;
}
}
return false;
}
示例5: assertTestRunner
import org.junit.runner.RunWith; //導入依賴的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;
}
示例6: noBeforeOnClasspath
import org.junit.runner.RunWith; //導入依賴的package包/類
@Test
public void noBeforeOnClasspath() throws Exception {
File libJar = tempFolder.newFile("lib.jar");
try (FileOutputStream fis = new FileOutputStream(libJar);
JarOutputStream jos = new JarOutputStream(fis)) {
addClassToJar(jos, RunWith.class);
addClassToJar(jos, JUnit4.class);
addClassToJar(jos, BlockJUnit4ClassRunner.class);
addClassToJar(jos, ParentRunner.class);
addClassToJar(jos, SuperTest.class);
addClassToJar(jos, SuperTest.class.getEnclosingClass());
}
compilationHelper
.addSourceLines(
"Test.java",
"import org.junit.runner.RunWith;",
"import org.junit.runners.JUnit4;",
"import " + SuperTest.class.getCanonicalName() + ";",
"@RunWith(JUnit4.class)",
"class Test extends SuperTest {",
" @Override public void setUp() {}",
"}")
.setArgs(Arrays.asList("-cp", libJar.toString()))
.doTest();
}
示例7: convertClass
import org.junit.runner.RunWith; //導入依賴的package包/類
/**
* @see junitconverter.stages.TestConversionStage#convertClass(junitconverter.testcase.TestCaseClass)
*/
public void convertClass(TestCaseClass testCase)
{
// This is a gigantic hack. We use a regex to search for classes/suites added to the suite.
// We start our search at the beginning of the suite method
List<String> lines = testCase.getLines().subList(testCase.getSuiteStartLine(), testCase.getSuiteEndLine() + 1);
StringBuilder builder = new StringBuilder();
builder.append('{');
for (String line : lines)
{
Matcher m = p.matcher(line);
if (m.find())
{
String testName = m.group(2);
builder.append(testName).append(".class, "); //$NON-NLS-1$
}
}
builder.append('}');
codeEditor.addAnnotation(testCase, SuiteClasses.class, builder.toString());
codeEditor.addAnnotation(testCase, RunWith.class, "Suite.class"); //$NON-NLS-1$
}
示例8: reportMethodAnnotation
import org.junit.runner.RunWith; //導入依賴的package包/類
@Override
public void reportMethodAnnotation(Class<? extends Annotation> annotation, String className, String methodName) {
try {
Class<?> clazz = getClass().getClassLoader().loadClass(className);
Class<?> type = null;
if (clazz.isAnnotationPresent(RunWith.class)) {
RunWith rwa = clazz.getAnnotation(RunWith.class);
if (rwa.value() == JExUnit.class) {
type = clazz;
}
}
if (annotation.isAnnotation() && (annotation == TestCommand.class || annotation == TestCommands.class)) {
for (Method m : clazz.getDeclaredMethods()) {
TestCommand[] testCommands = m.getDeclaredAnnotationsByType(TestCommand.class);
registerCommands(testCommands, type, m);
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
示例9: getTests
import org.junit.runner.RunWith; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public Set<BundleTest> getTests() throws InvalidSyntaxException {
final Set<BundleTest> allTests = new TreeSet<BundleTest>();
final Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
if (bundle.getState() == Bundle.ACTIVE) {
if ("true".equalsIgnoreCase(bundle.getHeaders().get("Alfresco-Dynamic-Extension"))) {
ApplicationContext applicationContext = ContextUtils.findApplicationContext(bundle.getSymbolicName());
if (applicationContext != null) {
Map<String,Object> testComponents = applicationContext.getBeansWithAnnotation(RunWith.class);
logger.debug("Looking for JUnit tests in {}", bundle.getSymbolicName());
for (Object test : testComponents.values()) {
BundleTest bundleTest = new BundleTest(test.getClass().getName(), bundle.getBundleId(), bundle.getSymbolicName());
logger.debug("Found test: {}", test);
allTests.add(bundleTest);
}
}
}
}
}
return allTests;
}
示例10: imports_urls_of_jars
import org.junit.runner.RunWith; //導入依賴的package包/類
@Test
public void imports_urls_of_jars() throws IOException {
Set<URL> urls = newHashSet(urlOf(Test.class), urlOf(RunWith.class));
assumeTrue("We can't completely ensure, that this will always be taken from a JAR file, though it's very likely",
"jar".equals(urls.iterator().next().getProtocol()));
JavaClasses classes = new ClassFileImporter().importUrls(urls)
.that(DescribedPredicate.not(type(Annotation.class))); // NOTE @Test and @RunWith implement Annotation.class
assertThat(classes).as("Number of classes at the given URLs").hasSize(2);
}
示例11: getRunnerAnnotations
import org.junit.runner.RunWith; //導入依賴的package包/類
@Override
public Annotation[] getRunnerAnnotations() {
Annotation[] allAnnotations = getTestClass().getAnnotations();
List<Annotation> annotationsWithoutRunWith = new ArrayList<>();
for (Annotation annotation : allAnnotations) {
if (!annotation.annotationType().equals(RunWith.class)) {
annotationsWithoutRunWith.add(annotation);
}
}
return annotationsWithoutRunWith.toArray(new Annotation[0]);
}
示例12: invoke
import org.junit.runner.RunWith; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Class<?> clazz = AopUtil.getBaseClassForAopObject(Class.forName(Thread.currentThread().getStackTrace()[8].
getClassName()));
if (clazz.isAnnotationPresent(RunWith.class) || clazz.isAnnotationPresent(ScenarioScoped.class)) {
pageObjectInvocationTracker.clearStack();
}
if (methodInvocation.getMethod().getDeclaringClass().isAnnotationPresent(PageObject.class)) {
pageObjectInvocationTracker.add(clazz, methodInvocation.getThis());
}
return methodInvocation.proceed();
}
示例13: isApplicable
import org.junit.runner.RunWith; //導入依賴的package包/類
private <I> boolean isApplicable(Class<? super I> rawType) {
boolean result;
if (rawType.isAnnotationPresent(RunWith.class)
&& !rawType.isAnnotationPresent(CucumberOptions.class)) {
result = true;
} else {
result = isStepsImplementationClass(rawType);
}
return result;
}
示例14: getRunnerAnnotations
import org.junit.runner.RunWith; //導入依賴的package包/類
@Override
protected Annotation[] getRunnerAnnotations() {
Annotation[] allAnnotations = super.getRunnerAnnotations();
Annotation[] annotationsWithoutRunWith = new Annotation[allAnnotations.length - 1];
int i = 0;
for (Annotation annotation: allAnnotations) {
if (!annotation.annotationType().equals(RunWith.class)) {
annotationsWithoutRunWith[i] = annotation;
++i;
}
}
return annotationsWithoutRunWith;
}
示例15: testClassWithoutPersistenceContextField
import org.junit.runner.RunWith; //導入依賴的package包/類
@Test
public void testClassWithoutPersistenceContextField() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
final JpaUnitRunner runner = new JpaUnitRunner(cut);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class);
verify(listener).testFailure(failureCaptor.capture());
final Failure failure = failureCaptor.getValue();
assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class));
assertThat(failure.getException().getMessage(), containsString("EntityManagerFactory or EntityManager field annotated"));
}