Search in sources :

Example 11 with TestFramework

use of com.intellij.testIntegration.TestFramework in project intellij-community by JetBrains.

the class TestUtils method isJUnitTestMethod.

public static boolean isJUnitTestMethod(@Nullable PsiMethod method) {
    if (method == null)
        return false;
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null)
        return false;
    final TestFramework framework = TestFrameworks.detectFramework(containingClass);
    return framework != null && framework.getName().startsWith("JUnit") && framework.isTestMethod(method);
}
Also used : TestFramework(com.intellij.testIntegration.TestFramework)

Example 12 with TestFramework

use of com.intellij.testIntegration.TestFramework in project intellij-community by JetBrains.

the class TestUtils method isAnnotatedTestMethod.

public static boolean isAnnotatedTestMethod(@Nullable PsiMethod method) {
    if (method == null)
        return false;
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null)
        return false;
    final TestFramework testFramework = TestFrameworks.detectFramework(containingClass);
    if (testFramework == null)
        return false;
    if (testFramework.isTestMethod(method)) {
        final String testFrameworkName = testFramework.getName();
        return testFrameworkName.equals("JUnit4") || testFrameworkName.equals("JUnit5");
    }
    return false;
}
Also used : TestFramework(com.intellij.testIntegration.TestFramework)

Example 13 with TestFramework

use of com.intellij.testIntegration.TestFramework in project intellij-community by JetBrains.

the class JUnit5ConverterInspection method buildVisitor.

@Override
public BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {

        @Override
        public void visitClass(PsiClass aClass) {
            TestFramework framework = TestFrameworks.detectFramework(aClass);
            if (framework == null || !"JUnit4".equals(framework.getName())) {
                return;
            }
            if (!canBeConvertedToJUnit5(aClass))
                return;
            registerClassError(aClass);
        }
    };
}
Also used : BaseInspectionVisitor(com.siyeh.ig.BaseInspectionVisitor) TestFramework(com.intellij.testIntegration.TestFramework)

Example 14 with TestFramework

use of com.intellij.testIntegration.TestFramework in project intellij-community by JetBrains.

the class TestDataGuessByExistingFilesUtil method getTestName.

@Nullable
private static String getTestName(@NotNull PsiMethod method) {
    final PsiClass psiClass = PsiTreeUtil.getParentOfType(method, PsiClass.class);
    if (psiClass == null) {
        return null;
    }
    TestFramework framework = TestFrameworks.detectFramework(psiClass);
    if (framework == null || isUtilityMethod(method, psiClass, framework)) {
        return null;
    }
    return getTestName(method.getName());
}
Also used : TestFramework(com.intellij.testIntegration.TestFramework) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with TestFramework

use of com.intellij.testIntegration.TestFramework in project intellij-community by JetBrains.

the class JUnit5AcceptanceTest method testFrameworkDetection.

@Test
void testFrameworkDetection() {
    doTest(() -> {
        PsiClass aClass = myFixture.addClass("class MyTest {@org.junit.jupiter.api.Test void method() {}}");
        assertNotNull(aClass);
        TestFramework framework = TestFrameworks.detectFramework(aClass);
        assertTrue(framework instanceof JUnit5Framework, framework.getName());
    });
}
Also used : TestFramework(com.intellij.testIntegration.TestFramework) PsiClass(com.intellij.psi.PsiClass) JUnit5Framework(com.intellij.execution.junit.JUnit5Framework) Test(org.junit.jupiter.api.Test)

Aggregations

TestFramework (com.intellij.testIntegration.TestFramework)15 Editor (com.intellij.openapi.editor.Editor)3 PsiClass (com.intellij.psi.PsiClass)3 Nullable (org.jetbrains.annotations.Nullable)3 FileTemplateDescriptor (com.intellij.ide.fileTemplates.FileTemplateDescriptor)2 Project (com.intellij.openapi.project.Project)2 Computable (com.intellij.openapi.util.Computable)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 JavaTestFramework (com.intellij.testIntegration.JavaTestFramework)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 CodeInsightUtil (com.intellij.codeInsight.CodeInsightUtil)1 FileModificationService (com.intellij.codeInsight.FileModificationService)1 Template (com.intellij.codeInsight.template.Template)1 JUnit5Framework (com.intellij.execution.junit.JUnit5Framework)1 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)1 FileTemplateUtil (com.intellij.ide.fileTemplates.FileTemplateUtil)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1