Skip to content

Initilial implementation of Spring test classes code generation #1788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 22, 2023

Conversation

sofurihafe
Copy link
Member

@sofurihafe sofurihafe commented Feb 13, 2023

Description

This PR adds support for necessary test class fields rendering (see InjectMocks, Mock below).
Also, in case of mocks it constructs them in test method (see (when(...))).

@Service
public class OrderService {
    @Autowired
    private OrderRepository orderRepository;

    public List<Order> getOrders() {
        return orderRepository.findAll();
    }
}
public final class OrderServiceTest {
    @InjectMocks
    public OrderService orderService;

    @Mock
    public OrderRepository orderRepositoryMock;

    public AutoCloseable mockitoCloseable;

    @BeforeEach
    public void setUp() {
        mockitoCloseable = openMocks(this);
    }

    @AfterEach
    public void tearDown() throws Exception {
        mockitoCloseable.close();
    }

    @Test
    public void testGetOrders1() {
        (when(orderRepositoryMock.findAll())).thenReturn(((List) null));

        List actual = orderService.getOrders();

        assertNull(actual);
    }
}

Fixes nothing, adds new feature.

How to test

Automated tests

No automated tests are present at this moment.

Manual tests

Tested manually on a third-party Spring project.

@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch 5 times, most recently from 5164396 to 1d0680a Compare February 14, 2023 18:31
@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch 3 times, most recently from 5df5bc2 to 900eefb Compare February 18, 2023 15:45
@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch from b144498 to f213dde Compare February 27, 2023 11:28
@EgorkaKulikov
Copy link
Collaborator

Currently crashed on the following method from out sample project:

public List<Order> getOrders(boolean flag) {
        if (flag) {
            return orderRepository.findAll();
        }

        return new ArrayList<>();
    }

Crash reason is:

        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        /* class org.utbot.framework.plugin.api.UtAssembleModel cannot be cast to class org.utbot.framework.plugin.api.UtCompositeModel (org.utbot.framework.plugin.api.UtAssembleModel and
        org.utbot.framework.plugin.api.UtCompositeModel are in unnamed module of loader 'app') */

@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch 2 times, most recently from ecde00f to dbd5d6b Compare February 28, 2023 16:51
@sofurihafe sofurihafe requested a review from Damtev March 1, 2023 07:03
@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch from dbd5d6b to 8dd9909 Compare March 1, 2023 08:13
@sofurihafe sofurihafe force-pushed the andrey-t/test_class_fields_rendering branch 2 times, most recently from 0efe234 to 1183fab Compare March 6, 2023 08:13
@sofurihafe sofurihafe marked this pull request as ready for review March 13, 2023 11:51
@EgorkaKulikov EgorkaKulikov force-pushed the andrey-t/test_class_fields_rendering branch 4 times, most recently from 49b9a34 to 3c1fd09 Compare March 21, 2023 12:41
@EgorkaKulikov EgorkaKulikov force-pushed the andrey-t/test_class_fields_rendering branch from 43f0728 to 9885645 Compare March 21, 2023 15:03
@EgorkaKulikov EgorkaKulikov self-requested a review March 21, 2023 15:06
@EgorkaKulikov EgorkaKulikov force-pushed the andrey-t/test_class_fields_rendering branch from 9885645 to a88dc91 Compare March 21, 2023 15:06
@EgorkaKulikov EgorkaKulikov removed their request for review March 21, 2023 15:06
Copy link
Member

@Damtev Damtev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some performance and minor issues

@EgorkaKulikov EgorkaKulikov changed the title Support test class fields rendering (Spring support) Initilial implementation of Spring test classes code generation Mar 22, 2023
@EgorkaKulikov EgorkaKulikov self-requested a review March 22, 2023 12:24
@EgorkaKulikov EgorkaKulikov merged commit a0e145f into main Mar 22, 2023
@EgorkaKulikov EgorkaKulikov deleted the andrey-t/test_class_fields_rendering branch March 22, 2023 14:07
@alisevych
Copy link
Member

alisevych commented Mar 23, 2023

@sofurihafe @EgorkaKulikov @Damtev
Please do not forget to add/check ctg- and comp labels to the PRs

@EgorkaKulikov EgorkaKulikov added comp-codegen Issue is related to code generator ctg-enhancement New feature, improvement or change request labels Mar 24, 2023
@alisevych alisevych added the comp-spring Issue is related to Spring projects support label Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants