junit 5: warn about junit 3 methods inside classes with junit 5 annotations (IDEA-163651)

This commit is contained in:
Anna.Kozlova
2016-11-07 18:56:11 +01:00
parent 08c5a244c3
commit 68b073041c
4 changed files with 35 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* 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.
@@ -75,7 +75,7 @@ public class JUnit3StyleTestMethodInJUnit4ClassInspection extends BaseInspection
if (!TestUtils.isRunnable(method)) {
return;
}
if (TestUtils.isJUnit4TestMethod(method)) {
if (TestUtils.isAnnotatedTestMethod(method)) {
return;
}
final PsiClass containingClass = method.getContainingClass();
@@ -1,7 +1,7 @@
<html>
<body>
Reports JUnit 3 style test methods which are located inside a class
which does not extend the abstract JUnit 3 class <b>TestCase</b> and contains JUnit 4 <b>@Test</b> annotated methods.
which does not extend the abstract JUnit 3 class <b>TestCase</b> and contains JUnit 4/JUnit 5 <b>@Test</b> annotated methods.
In addition to being confusing such test methods will not be run.
<!-- tooltip end -->
<p>
@@ -0,0 +1,22 @@
/*
* 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.
*/
import org.junit.jupiter.api.Test;
public class SimpleJUnit5 {
@Test
public void testIt() {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* 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.
@@ -26,6 +26,7 @@ public class JUnit3StyleTestMethodInJUnit4ClassInspectionTest extends LightInspe
public void testJUnit3StyleTestMethodInJUnit4Class() { doTest(); }
public void testBeforeAnnotationUsed() { doTest(); }
public void testSimpleJUnit5() { doTest(); }
@Nullable
@Override
@@ -51,6 +52,14 @@ public class JUnit3StyleTestMethodInJUnit4ClassInspectionTest extends LightInspe
"import java.lang.annotation.Target;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Test {}",
"package org.junit.jupiter.api;" +
"import java.lang.annotation.ElementType;" +
"import java.lang.annotation.Retention;" +
"import java.lang.annotation.RetentionPolicy;" +
"import java.lang.annotation.Target;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Test {}"
};
}