Skip to content

Custom JUnit TestRunner #352

@JeffFaer

Description

@JeffFaer

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...

My proposal:

  • Create a TestRunner which will report each expected diagnostic as a separate test case with a specific name. Let's call it ErrorProneRunner.
  • Annotate each *(Positive|Negative)Cases.java file with @RunWith(ErrorProneRunner.class)
  • Create dummy packages in testdata for Stringly typed source code and tell the ErrorProneRunner to do its thing (possibly with an annotation on *PositiveCases.java?)
  • Replace // BUG: Diagnostic contains: XXX with @ExpectDiagnostic("specific expectation message"):
@interface ExpectDiagnostic {
    String value();
    String[] messageContains() default {};
    String[] fixesContain() default {};
    .
    .
}
  • We can also add the counterpoint @DoNotExpectDiagnostic

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions