Skip to content

Improve Spring unit tests generation for classes with non-injected fields #2328

@EgorkaKulikov

Description

@EgorkaKulikov

Description

Currently we use the following approach in unit tests generation.

The code

class A(
  B b
  C c

  methodUnderTest()
}

is converted to

class TestClass {
  @InjectMocks A a
  @Mock B b
  @Mock C c
}

and a mapping from type to the list of models is used
B -> m11, m12, ...
C -> m21, m22, ...

There are some possible problems in this approach:

  1. What if the constructor contains some non-injectible field?
class A(List<int> ints)
  1. What if the constructor contains two fields of same non-injectible type?
class A(List<int> ints1, List<int> ints2)
  1. Is it possible to create some util class (may be nested or inner), that does not use Spring and has the following constructor
class Utils(B b1, B b2)
  1. Is it a used practice to pass to constructor some non-injectible type with injectible ones? What should we do?
class A(B b, List<int> ints)

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

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions