Skip to content

Failing assertion is generated for Spring class  #2060

Closed
@EgorkaKulikov

Description

@EgorkaKulikov

Description

Let's generate tests for the following code:

private EntityManager em;

public List<User> listUsers() {
        return em.createQuery("from User ", User.class).getResultList();
    }

UtBot automatically detects that it is a Spring project, NoConfiguration mode is selected.

Generated test looks as follows:

@Mock
public TypedQuery typedQueryMock;

@Test
@DisplayName("listUsers: EntityManagerCreateQuery -> return em.createQuery(\"from User \", User.class).getResultList()")
public void testListUsers_TypedQueryGetResultList() {
	(when(entityManagerMock.createQuery(any(), any()))).thenReturn(typedQueryMock);

	List actual = userDaoImp.listUsers();

	assertNull(actual);
}

TypedQuery type fully qualified name is javax.persistence.TypedQuery

Expected behavior

UtBot generates only passing tests.

Actual behavior

Generated test fails on the assertion.

Visual proofs (screenshots, logs, images)

image

Additional context

The problem requires investigation, there are several possible situations:

  • assertion is correct, but mocking is configured badly
  • assertion is generated incorrectly
  • there is a bug in engine that leads to incorrect test

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-springIssue is related to Spring projects supportctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions