Search in sources :

Example 21 with TestClass

use of org.junit.runners.model.TestClass in project junit4 by junit-team.

the class RuleMemberValidatorTest method methodRejectNonStaticClassRule.

@Test
public void methodRejectNonStaticClassRule() {
    TestClass target = new TestClass(MethodTestWithNonStaticClassRule.class);
    CLASS_RULE_METHOD_VALIDATOR.validate(target, errors);
    assertOneErrorWithMessage("The @ClassRule 'getTemporaryFolder' must be static.");
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test)

Example 22 with TestClass

use of org.junit.runners.model.TestClass in project Main by SpartanRefactoring.

the class MetaTester method runChild.

@Override
@SuppressWarnings("unused")
protected void runChild(final FrameworkMethod __, final RunNotifier n) {
    if (hasRan)
        return;
    final Class<?> newTestClass = new ASTTestClassGenerator(testClass).generate(testClass.getSimpleName() + "_Meta", sourceFile);
    final TestSuite suite = new TestSuite(newTestClass);
    suite.run(new TestResult());
    try {
        new BlockJUnit4ClassRunnerWithParametersFactory().createRunnerForTestWithParameters(new TestWithParameters(" ", new TestClass(newTestClass), an.empty.list())).run(n);
    } catch (final InitializationError ignore) {
    /**/
    }
    // Uncomment this to run the original test as well
    /* super.runChild(method, notifier); */
    hasRan = true;
}
Also used : TestWithParameters(org.junit.runners.parameterized.TestWithParameters) TestSuite(junit.framework.TestSuite) InitializationError(org.junit.runners.model.InitializationError) TestResult(junit.framework.TestResult) BlockJUnit4ClassRunnerWithParametersFactory(org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory) TestClass(org.junit.runners.model.TestClass)

Example 23 with TestClass

use of org.junit.runners.model.TestClass in project alchemy-test by SirWellington.

the class TestClassInjectorsTest method testPopulateGeneratedFieldsWithBadEnum.

@Test
public void testPopulateGeneratedFieldsWithBadEnum() throws Exception {
    System.out.println("testPopulateGeneratedFieldsWithBadEnum");
    TestClass testClass = new TestClass(BadEnumTest.class);
    BadEnumTest instance = new BadEnumTest();
    assertThrows(() -> TestClassInjectors.populateGeneratedFields(testClass, instance)).isInstanceOf(IllegalArgumentException.class);
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest)

Example 24 with TestClass

use of org.junit.runners.model.TestClass in project alchemy-test by SirWellington.

the class TestClassInjectorsTest method testPopulateGeneratedFields.

@Test
public void testPopulateGeneratedFields() throws Exception {
    System.out.println("testPopulateGeneratedFields");
    TestClass testClass = new TestClass(FakeTestClass.class);
    FakeTestClass instance = new FakeTestClass();
    TestClassInjectors.populateGeneratedFields(testClass, instance);
    instance.setUp();
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest)

Example 25 with TestClass

use of org.junit.runners.model.TestClass in project intellij-community by JetBrains.

the class GuiTestRunner method loadClassesWithNewPluginClassLoader.

private void loadClassesWithNewPluginClassLoader() throws Exception {
    //ensure that IDEA has been initialized.
    IdeTestApplication.getInstance();
    ParentPlugin testParentPluginAnnotation = getTestClass().getAnnotation(ParentPlugin.class);
    assertNotNull(testParentPluginAnnotation);
    String dependentPluginId = testParentPluginAnnotation.pluginId();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    String classPath = getTestClass().getJavaClass().getCanonicalName().replace(".", "/").concat(".class");
    URL resource = classLoader.getResource(classPath);
    assertNotNull(resource);
    String pathToTestClass = resource.getPath();
    String containingFolderPath = pathToTestClass.substring(0, pathToTestClass.length() - classPath.length());
    URL urlToTestClass = (new File(containingFolderPath)).toURI().toURL();
    IdeaPluginDescriptor parentPluginDescriptor = PluginManager.getPlugin(PluginId.getId(dependentPluginId));
    assertNotNull(parentPluginDescriptor);
    ClassLoader parentPluginClassLoader = parentPluginDescriptor.getPluginClassLoader();
    ClassLoader[] classLoaders = { parentPluginClassLoader };
    String testPluginId = dependentPluginId + ".guitest";
    PluginClassLoader testPluginClassLoader = new PluginClassLoader(Collections.singletonList(urlToTestClass), classLoaders, PluginId.getId(testPluginId), null, null);
    Thread.currentThread().setContextClassLoader(testPluginClassLoader);
    Class<?> testClass = getTestClass().getJavaClass();
    myTestClass = new TestClass(testPluginClassLoader.loadClass(testClass.getName()));
}
Also used : PluginClassLoader(com.intellij.ide.plugins.cl.PluginClassLoader) TestClass(org.junit.runners.model.TestClass) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) File(java.io.File) URL(java.net.URL) PluginClassLoader(com.intellij.ide.plugins.cl.PluginClassLoader)

Aggregations

TestClass (org.junit.runners.model.TestClass)60 Test (org.junit.Test)41 FrameworkMethod (org.junit.runners.model.FrameworkMethod)12 PotentialAssignment (org.junit.experimental.theories.PotentialAssignment)6 SpecificDataPointsSupplier (org.junit.experimental.theories.internal.SpecificDataPointsSupplier)6 Annotation (java.lang.annotation.Annotation)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PluginClassLoader (com.intellij.ide.plugins.cl.PluginClassLoader)2 HashMap (java.util.HashMap)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 Interaction (au.com.dius.pact.model.Interaction)1 Pact (au.com.dius.pact.model.Pact)1 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)1 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)1 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)1 Provider (au.com.dius.pact.provider.junit.Provider)1