Skip to content

Introduce more complicated NPE analysis for Spring applications #2034

Closed
@EgorkaKulikov

Description

@EgorkaKulikov

Description

Let's generate tests for the following code snippet

  public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Transactional
    @Override
    public void add(User user) {
        userDao.add(user);
    }

The following test is generated

@Test
  public void testListUsers_UserDaoListUsers_1() {
      /* This test fails because method [web.service.UserServiceImpl.listUsers] produces [java.lang.NullPointerException]
          web.service.UserServiceImpl.listUsers(UserServiceImpl.java:28) */
      userServiceImpl.listUsers();
  }

Actually, this test passes :)
And this behavior is correct because NPE is impossible on objects injected with Mock and InjectMocks.

Expected behavior

NPE tests should be generated only when this exception is really possible. We need to tune Symbolic engine for that.

Metadata

Metadata

Assignees

Labels

comp-springIssue is related to Spring projects supportcomp-symbolic-engineIssue is related to the symbolic execution enginectg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions