Comments (11)
Original comment posted by [email protected] on 2012-07-16 at 07:51 PM
Note that JUnit4-style tests should not extend TestCase, but perhaps that should be a warning, not an error.
Note that JUnit4-style tests do not need to have method names that start with "test", but they do need to be annotated with @Test. It would be great to detect at compile time methods in JUnit4-style tests that are 1) public, 2) contain no arguments, 3) have a method name starting with "test", and 4) are not annotated with @Test. JUnit will not fail a test that contains a method like this, while it will fail a test that uses @BeforeClass in a non-public or non-static method.
from error-prone.
Original comment posted by [email protected] on 2012-07-16 at 10:43 PM
Issue #24 has been merged into this issue.
from error-prone.
Original comment posted by [email protected] on 2012-08-27 at 06:01 PM
Additional cases to check for from yoavtz:
- A class ending with the word Test that is not annotated with @RunWith
- A method starting with the word "test" that is not annotated with @Test (possibly only in classes annotated with @RunWith(JUnit4.class)
- A method called setup or setUp that is not annotated with @Before
- A method called teardown or tearDown that is not annotated with @After
from error-prone.
Original comment posted by [email protected] on 2013-02-11 at 09:38 PM
(No comment entered for this change.)
Status: Accepted
Labels: -Priority-Medium, Priority-High
from error-prone.
Original comment posted by [email protected] on 2013-03-18 at 05:43 PM
A JUnit 3 case from jwray:
- A method starting with the word "Test" (uppercase), which doesn't run because JUnit 3 expects test methods to start with a lowercase "test". Note that standard Java style expects methods to start with a lowercase letter anyway.
from error-prone.
Original comment posted by [email protected] on 2013-03-18 at 11:58 PM
(No comment entered for this change.)
Owner: [email protected]
from error-prone.
Original comment posted by [email protected] on 2013-03-21 at 12:04 AM
Another case from pepstein:
You have a JUnit 3 test (no @RunWith) but use @Test annotations on your methods. Those tests won't run if they don't match the JUnit 3 naming conventions.
from error-prone.
Original comment posted by [email protected] on 2013-04-09 at 05:35 PM
I committed a check for JUnit4-style tests that do not have an @Test annotation. Will be released in v0.9.13.
from error-prone.
Original comment posted by [email protected] on 2013-08-19 at 10:38 PM
It's perfectly valid to have a class ending with the word Test that is not annotated with @RunWith and does not extend junit.framework.TestCase. JUnit4 does not require that test classes have a @RunWith annotation
from error-prone.
Original comment posted by [email protected] on 2013-08-19 at 11:09 PM
kcooney, acknowledged.
from error-prone.
Original comment posted by [email protected] on 2013-10-01 at 04:40 PM
Just noting that if BeforeClass.java could have @RequiredModifiers({PUBLIC, STATIC}) added to it, that would take care of this. Of course that's probably not possible.
from error-prone.
Related Issues (20)
- Unhandled exception was thrown with Java 21 HOT 3
- Var false possitives detected when NPE (via nullaway) detected
- Invalid severity could have explicit error message
- InvalidInlinteTag: @snippet javadoc false positive
- Crash in JUnitIncompatibleType HOT 4
- MultipleNullnessAnnotations inconsistent on nested class HOT 5
- An unhandled exception was thrown by the Error Prone static analysis plugin HOT 3
- MultipleNullnessAnnotations shouldn't consider Validation Annotations HOT 3
- class file for com.google.errorprone.annotations.RestrictedInheritance not found HOT 3
- java.lang.ClassCastException: class com.sun.tools.javac.tree.JCTree$JCBinary cannot be cast to class com.sun.source.tree.ParenthesizedTree (com.sun.tools.javac.tree.JCTree$JCBinary and com.sun.source.tree.ParenthesizedTree are in module jdk.compiler of loader 'app') HOT 1
- `@Immutable` does not recognize safe array handling HOT 3
- Error-prone patching cannot be used in bazel
- Crash with annotated nested types
- NPE with nested instanceof patterns
- [IllegalAccessError] An unhandled exception was thrown by the Error Prone static analysis plugin. HOT 2
- An unhandled exception was thrown by the Error Prone static analysis plugin. HOT 1
- SystemConsoleNull should consider the case where `System.console() == null` HOT 3
- StringCharset BugPattern summary is not helpful
- An unhandled exception was thrown by the Error Prone static analysis HOT 1
- Update JDK from 11 to 21 and errorprone breaks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from error-prone.