-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Assignees
@tochilinak
Description
Description
Bad example for UTBot symbolic execution engine.
To Reproduce
Steps to reproduce the behavior:
- Create project in IntelliJ Idea with the following code:
public class Main { int func(int x, int y, int z) { assert (y == 0); while (y < 10000) y += 1; if (x == y || z == y) return 1; return 2; } }
- Use plugin to generate tests (with and without fuzzing).
Expected behavior
All lines were covered by generated tests.
Actual behavior
No tests with return value 1
were generated.
Visual proofs (screenshots, logs, images)
Tests generated with 100% symbolic execution:
public final class MainTest { ///region Test suites for executable com.company.Main.func ///region SYMBOLIC EXECUTION: EXPLICITLY THROWN UNCHECKED EXCEPTIONS for method func(int, int, int) /** * @utbot.classUnderTest {@link Main} * @utbot.methodUnderTest {@link Main#func(int, int, int)} * @utbot.executesCondition {@code (assert (y == 0);): True} * @utbot.executesCondition {@code (assert (y == 0);): True} * @utbot.throwsException {@link AssertionError} in: assert (y == 0); */ @Test @DisplayName("func: assert (y == 0) -> ThrowAssertionError") public void testFunc_ThrowAssertionError() { Main main = new Main(); /* This test fails because method [com.company.Main.func] produces [java.lang.AssertionError] com.company.Main.func(Main.java:5) */ main.func(-255, -255, -255); } ///endregion ///endregion }
Tests generated with 5% fuzzing:
public final class MainTest { ///region Test suites for executable com.company.Main.func ///region SYMBOLIC EXECUTION: EXPLICITLY THROWN UNCHECKED EXCEPTIONS for method func(int, int, int) /** * @utbot.classUnderTest {@link Main} * @utbot.methodUnderTest {@link Main#func(int, int, int)} * @utbot.executesCondition {@code (assert (y == 0);): True} * @utbot.executesCondition {@code (assert (y == 0);): True} * @utbot.throwsException {@link AssertionError} in: assert (y == 0); */ @Test @DisplayName("func: assert (y == 0) -> ThrowAssertionError") public void testFunc_ThrowAssertionError() { Main main = new Main(); /* This test fails because method [com.company.Main.func] produces [java.lang.AssertionError] com.company.Main.func(Main.java:5) */ main.func(-255, -255, -255); } ///endregion ///region OTHER: SUCCESSFUL EXECUTIONS for method func(int, int, int) @Test public void testFunc1() { Main main = new Main(); int actual = main.func(0, 0, 0); assertEquals(2, actual); } ///endregion ///endregion }
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
In Progress