Utbot Maven Plugin is a maven plugin for generating tests and creating SARIF-reports.
The generateTestsAndSarifReport
maven task generates tests and SARIF-reports for all classes in your project (or only for classes specified in the configuration).
In addition, it creates one big SARIF-report containing the results from all the processed files.
TODO: The plugin has not been published yet.
-
Apply the plugin:
<build> <plugins> <plugin> <groupId>org.utbot</groupId> <artifactId>utbot-maven</artifactId> <version>1.0-SNAPSHOT</version> </plugin> </plugins> </build>
-
Run maven task
utbot:generateTestsAndSarifReport
to create a report.
For example, the following configuration may be used:
<configuration>
<targetClasses>
<param>com.abc.Main</param>
<param>com.qwerty.Util</param>
</targetClasses>
<projectRoot>C:/.../SomeDirectory</projectRoot>
<generatedTestsRelativeRoot>target/generated/test</generatedTestsRelativeRoot>
<sarifReportsRelativeRoot>target/generated/sarif</sarifReportsRelativeRoot>
<markGeneratedTestsDirectoryAsTestSourcesRoot>true</markGeneratedTestsDirectoryAsTestSourcesRoot>
<testPrivateMethods>false</testPrivateMethods>
<projectType>purejvm</projectType>
<testFramework>junit5</testFramework>
<mockFramework>mockito</mockFramework>
<generationTimeout>60000L</generationTimeout>
<codegenLanguage>java</codegenLanguage>
<mockStrategy>other-packages</mockStrategy>
<staticsMocking>mock-statics</staticsMocking>
<forceStaticMocking>force</forceStaticMocking>
<classesToMockAlways>
<param>org.slf4j.Logger</param>
<param>java.util.Random</param>
</classesToMockAlways>
</configuration>
Note: All configuration fields have default values, so there is no need to configure the plugin if you don't want to.
Description of fields:
-
targetClasses
–- Classes for which the SARIF-report will be created. Uses all source classes from the user project if this list is empty.
- By default, an empty list is used.
-
projectRoot
–- Absolute path to the root of the relative paths in the SARIF-report.
- By default, the root of your project is used.
-
generatedTestsRelativeRoot
–- Relative path (against module root) to the root of the generated tests.
- By default,
'target/generated/test'
is used.
-
sarifReportsRelativeRoot
–- Relative path (against module root) to the root of the SARIF reports.
- By default,
'target/generated/sarif'
is used.
-
markGeneratedTestsDirectoryAsTestSourcesRoot
–- TODO: It has not been supported yet.
- Mark the directory with generated tests as
test sources root
or not. - By default,
true
is used.
-
testPrivateMethods
–- Generate tests for private methods or not.
- By default,
false
is used.
-
projectType
–- The type of project being analyzed.
- Can be one of:
'purejvm'
(by default)'spring'
'python'
'javascript'
-
testFramework
–- The name of the test framework to be used.
- Can be one of:
'junit4'
'junit5'
(by default)'testng'
-
mockFramework
–- The name of the mock framework to be used.
- Can be one of:
'mockito'
(by default)
-
generationTimeout
–- Time budget for generating tests for one class (in milliseconds).
- By default, 60 seconds is used.
-
codegenLanguage
–- The language of the generated tests.
- Can be one of:
'java'
(by default)'kotlin'
-
mockStrategy
–- The mock strategy to be used.
- Can be one of:
'no-mocks'
– do not use mock frameworks at all'other-packages'
– mock all classes outside the current package except system ones (by default)'other-classes'
– mock all classes outside the class under test except system ones
-
staticsMocking
–- Use static methods mocking or not.
- Can be one of:
'do-not-mock-statics'
'mock-statics'
(by default)
-
forceStaticMocking
–- Forces mocking static methods and constructors for
classesToMockAlways
classes or not. - Can be one of:
'force'
(by default)'do-not-force'
- Note: We force static mocking independently on this setting for some classes (e.g.
java.util.Random
).
- Forces mocking static methods and constructors for
-
classesToMockAlways
–- Classes to force mocking theirs static methods and constructors.
- By default, some internal classes are used.
If you want to change the source code of the plugin or even the whole utbot-project, you need to do the following:
- Publish plugin to the local maven repository:
utbot-maven/publishing/publishToMavenLocal
- Add the plugin to your project (see the section How to use).
To change the log level run the generateTestsAndSarifReport
task with the appropriate flag.
For example, mvn utbot:generateTestsAndSarifReport --debug
Note that the internal maven log information will also be shown.