Skip to content

Correct field modifiers in Spring test classes #2325

@EgorkaKulikov

Description

@EgorkaKulikov

Description

Try to generate unit or integration tests for an arbitrary Spring project.
All class fields, annotated with @InjectMocks, @Mock, @Autowired, or mockitoCloseable field are now public.

Example:

image

In accordance with Mockito documentation, we should (https://javadoc.io/static/org.mockito/mockito-core/3.5.6/org/mockito/MockitoAnnotations.html)

  • Make @InjectMock, @Mock and @Autowired fields private
  • Make mockitoCloseable variable private
  • Still use public for setUp and tearDown methods.

Also it is better to locate setUp and tearDown under test methods, not above them.

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-springIssue is related to Spring projects supportctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions