Recipe Name:
JUnit 5: Incorrect method signature for annotation (All)
Description:
The annotations on this method require it to have a void return type, not be private, and be static.
Level:
error
Language:
  • java
  • kotlin
Tags:
  • testing
  • framework specific
  • JUnit 5
  • quality
Documentation

As mentioned in the JUnit JavaDoc, methods annotated with BeforeAll or AfterAll should be made non-private, static and should have a void return type in order to function correctly.

Before

  After

  
  References
  
  

Recipe
id: scw:java:junit5:annotation-method-signature-all
version: 10
metadata:
  name: 'JUnit 5: Incorrect method signature for annotation (All)'
  shortDescription: The annotations on this method require it to have a void return type, not be private, and be static.
  level: error
  language: java; kotlin
  enabled: true
  comment: ""
  descriptionFile: descriptions/JUnit_5__Incorrect_method_signature_for_annotation__All_.html
  tags: testing;framework specific;JUnit 5;quality
search:
  method:
    annotation:
      label: beforeeachannotation
      type:
        reference:
          matches: org.junit.jupiter.api.(Before|After)All
        checkInheritance: true
    anyOf:
    - modifier: private
    - returnType:
        not: void
        checkInheritance: true
    - without:
        modifier: static
availableFixes:
- name: Remove annotation
  actions:
  - remove:
      target: label:beforeeachannotation
- name: Change method to public static void
  actions:
  - changeModifiers:
      static: true
      visibility: public
  - changeType:
      type: void