Closed
Description
Description
If analyzed class has package-private (default) access - and there is a public or a package-private constructor - need to use the applicable constructor. Currently reflection is used and createInstance (String className) is generated.
To Reproduce
Preconditions:
- Open/create a project in IntelliJ Idea
- UTBotJava plugin is installed
Steps to reproduce the behavior:
- Add the following java class:
class A {
public int a = 0;
public int b = 7;
public A() {
}
A(int a, int b) {
this.a = a;
this.b = b;
}
int sum() {
return a + b;
}
}
- Generate Test with UTBot for this class
- Open the generated test
Expected behavior
Constructor call must be used to instantiate A object.
A a = new A(-255, -255);
Actual behavior
There is createInstance(String className) method generated.
It is used to instantiate A object in the test.
A a = ((A) createInstance("A"));
a.b = -255;
a.a = -255;
Environment
IDEA 2022.1.3
JDK 8
UTBotJava plugin build
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done