-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Labels
ctg-bugIssue is a bugIssue is a bug
Description
Description
Utbot intentionally sets outer class reference to null
to generate NPE exception.
To Reproduce
- In settings of UTBot set 'Code analysis' slider to 'Deeper'
- Generate tests for
Outer.Inner.test
method in following code:
public class Outer {
public void publicMethod() {
System.out.println("Outer.publicMethod");
}
class Inner {
void test() {
publicMethod();
}
}
}
Expected behavior
One test which invokes Outer.Inner.test()
is generated.
Actual behavior
Two tests are generated and second one fails with NPE. Note that test intentionally sets null
as reference to outer class, which causes NullPointerException. Such test seems not helpful for users and should not be generated.
@Test
@DisplayName("test: privateMethod() : True -> ThrowNullPointerException")
public void testTest_OuterPrivateMethod_1() throws Exception {
Inner inner = ((Inner) createInstance("org.test.Outer$Inner"));
setField(inner, "org.test.Outer$Inner", "this$0", null);
/* This test fails because method [org.test.Outer$Inner.test] produces [java.lang.NullPointerException]
org.test.Outer$Inner.test(Outer.java:10) */
inner.test();
}
Metadata
Metadata
Assignees
Labels
ctg-bugIssue is a bugIssue is a bug
Type
Projects
Status
Todo