Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T ticket
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,809
    • Issues 1,809
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Administrator
  • ticket
  • Issues
  • #839

Closed
Open
Created Sep 02, 2022 by Administrator@rootMaintainer

JUnit5 test classes and methods should have default package visibility

Created by: teerth-preprod[bot]

JUnit5 is more tolerant regarding the visibilities of Test classes than JUnit4, which required everything to be public.

In this context, JUnit5 test classes can have any visibility but private, however, it is recommended to use the default packagevisibility, which improves readability of code.

Noncompliant Code Example

import org.junit.jupiter.api.Test;public class MyClassTest { // Noncompliant - modifier can be removed  @Test  protected void test() { // Noncompliant - modifier can be removed    // ...  }}

Compliant Solution

import org.junit.jupiter.api.Test;class MyClassTest {  @Test  void test() {    // ...  }}

Exceptions

This rule does not raise an issue about private visibility, because private test methods and classes are systematicallyignored by JUnit5, without a proper warning. It's not a Code Smell but a Bug handled by the rule S5810.

See

  • JUnit 5 Test Classes and Methods

File Path: webgoat-integration-tests/src/test/java/org/owasp/webgoat/PasswordResetLessonTest.java:18

Mitigation: Remove this 'public' modifier.

https://preprod.armorcode.ai/#/findings/6891663

Assignee
Assign to
Time tracking