-
Notifications
You must be signed in to change notification settings - Fork 781
Open
Description
The current pattern for tests leaves something to be desired:
- Each *(Positive|Negative)Cases.java file generally contains several checks. It would be nice if each check was an individual test case (
@Test) so that it is easier to see exactly what is failing. - Many *Test.java classes contain
Stringly typed source code. It's a pain in the neck to format it and add imports. - This isn't Java 4 anymore, we have annotations! We could use an annotation instead of a comment to declare where we think errors are.
- Advantages:
- Easier to see what properties we can assert.
- Facilitates better documentation
- Disadvantages:
- We have to create a new class for the annotation
- It is harder to match an annotation type if you're only given a
String. But we do have access to the AST...
- Advantages:
My proposal:
- Create a
TestRunnerwhich will report each expected diagnostic as a separate test case with a specific name. Let's call itErrorProneRunner. - Annotate each *(Positive|Negative)Cases.java file with
@RunWith(ErrorProneRunner.class) - Create dummy packages in testdata for
Stringly typed source code and tell theErrorProneRunnerto do its thing (possibly with an annotation on *PositiveCases.java?) - Replace
// BUG: Diagnostic contains: XXXwith@ExpectDiagnostic("specific expectation message"):
@interface ExpectDiagnostic {
String value();
String[] messageContains() default {};
String[] fixesContain() default {};
.
.
}
- We can also add the counterpoint
@DoNotExpectDiagnostic
Thoughts?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels