mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit 5: recognize test factory as test (IDEA-160177)
This commit is contained in:
@@ -43,6 +43,7 @@ public class JUnitUtil {
|
||||
@NonNls private static final String TESTSUITE_CLASS = "junit.framework.TestSuite";
|
||||
@NonNls public static final String TEST_ANNOTATION = "org.junit.Test";
|
||||
@NonNls public static final String TEST5_ANNOTATION = "org.junit.jupiter.api.Test";
|
||||
@NonNls public static final String TEST5_FACTORY_ANNOTATION = "org.junit.jupiter.api.TestFactory";
|
||||
@NonNls public static final String IGNORE_ANNOTATION = "org.junit.Ignore";
|
||||
@NonNls public static final String RUN_WITH = "org.junit.runner.RunWith";
|
||||
@NonNls public static final String DATA_POINT = "org.junit.experimental.theories.DataPoint";
|
||||
@@ -62,7 +63,9 @@ public class JUnitUtil {
|
||||
public static final String BEFORE_ALL_ANNOTATION_NAME = "org.junit.jupiter.api.BeforeAll";
|
||||
public static final String AFTER_ALL_ANNOTATION_NAME = "org.junit.jupiter.api.AfterAll";
|
||||
|
||||
private static final Collection<String> TEST_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(TEST_ANNOTATION, TEST5_ANNOTATION));
|
||||
private static final Collection<String> TEST_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(TEST_ANNOTATION,
|
||||
TEST5_ANNOTATION,
|
||||
TEST5_FACTORY_ANNOTATION));
|
||||
|
||||
private static final List<String> INSTANCE_CONFIGS = Arrays.asList(BEFORE_ANNOTATION_NAME, AFTER_ANNOTATION_NAME);
|
||||
private static final List<String> INSTANCE_5_CONFIGS = Arrays.asList(BEFORE_EACH_ANNOTATION_NAME, AFTER_EACH_ANNOTATION_NAME);
|
||||
|
||||
@@ -19,5 +19,7 @@
|
||||
<orderEntry type="module" module-name="junit5_rt" />
|
||||
<orderEntry type="library" name="junit5_rt" level="project" />
|
||||
<orderEntry type="library" name="opentest4j" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="execution-impl" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.junit5;
|
||||
|
||||
import com.intellij.execution.junit.JUnitUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.TestRunnerUtil;
|
||||
import com.intellij.testFramework.fixtures.*;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class JUnit5AcceptanceTest {
|
||||
|
||||
private JavaCodeInsightTestFixture myFixture;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(new DefaultLightProjectDescriptor());
|
||||
final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
|
||||
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl(true));
|
||||
myFixture.setUp();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFactoryMethods() {
|
||||
TestRunnerUtil.replaceIdeEventQueueSafely();
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
PsiClass aClass = myFixture.addClass("class MyTest {@org.junit.jupiter.api.TestFactory java.util.List<org.junit.jupiter.api.DynamicTest> tests() {return null;}}");
|
||||
PsiMethod factoryMethod = aClass.getMethods()[0];
|
||||
assertNotNull(factoryMethod);
|
||||
assertTrue(JUnitUtil.isTestAnnotated(factoryMethod));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user