Skip to content
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

Cg util class #689

Merged
merged 30 commits into from
Sep 1, 2022
Merged

Cg util class #689

merged 30 commits into from
Sep 1, 2022

Conversation

ArsenHD
Copy link
Collaborator

@ArsenHD ArsenHD commented Aug 8, 2022

Description

This MR allows moving all util methods that have previously been in the test class into a separate util class. The plugin will now generate utils in a separate class (org.utbot.runtime.utils.UtUtils).

If no util methods are required in the generated tests, then no util class will be generated. If the generated tests require util methods, but the tests do not use mocking, then a version of util class without mockito will be generated (when mocking is used, deepEquals util method is a bit different). Otherwise, when mocking is used, an util class with mockito usage will be produced.

For other components that use code generation the behavior may be different:

  • TestCodeGenerationPipeline - Util class is generated, but only in tests where we use checkAllCombinations(). We check all combinations of generation settings with and without util class. But this shouldn't take much time, because we check all combinations only for a couple of classes.
  • GenerateTestsAbstractCommand (CLI), GenerateTestsAndSarifReportFacade - we decided that these components should generate util class, but it is not implemented in this PR. For now they work as before, but in the future util class generation may be added.
  • UtBotJavaApi, Contest - we decided that these components should not generate util class. They work as before, util methods are generated directly in the test class.

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Automated Testing

Specify tests that help to verify the change automatically.

The following tests use function checkAllCombinations() that runs test generation with all configurations:
org.utbot.examples.codegen.CodegenExampleTest
org.utbot.examples.enums.ClassWithEnumTest#testOrdinal

Now all of these configurations also run with AND without a separate util class. This way the new feature is tested in the pipeline.

Manual Scenario

Note that util class can be overwritten if needed. This can be demonstrated and tested with the following actions:

  1. We generate tests that need no utils --> no util class produced
  2. Then we generate tests that do need utils (but with no mocks) --> util class without mockito produced
  3. After that we generate tests that do need utils with mocks --> existing util class is overwritten with a new one that uses mockito.

Checklist:

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@ArsenHD ArsenHD force-pushed the cg-util-class branch 2 times, most recently from ce1f2c8 to c7e564c Compare August 12, 2022 01:49
@ArsenHD ArsenHD force-pushed the cg-util-class branch 2 times, most recently from f96a8f1 to 2a3cf3f Compare August 30, 2022 10:41
ArsenHD added 22 commits August 31, 2022 19:39
This commit moves all util methods that have previously been in the test class into a separate module. This module is built into a shadow jar which needs to be added into the user's project dependencies in order for our generated tests to be able to use its functionality.
All util methods and data provider methods are static. In Kotlin they will be placed into a companion object.
Regular classes will be used for construction of util classes.
Rewrite util method provider classes and their usage. There are 3 kinds of providers: library, test class, util class file.
If no util methods are required, then util class will not be generated. Otherwise, we will generate an util class with or without Mockito usage, depending on whether Mockito is used in the tests or not. Note that whenever an util class with Mockito is required, it will be generated and it will rewrite a previous utils file if it exists. That's because the previous file could have been without Mockito.
@ArsenHD ArsenHD merged commit 779e053 into main Sep 1, 2022
@ArsenHD ArsenHD deleted the cg-util-class branch September 1, 2022 10:49
@ArsenHD ArsenHD mentioned this pull request Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants