use withHistory build ci/cd

38 views
Skip to first unread message

Isabel Garcia

unread,
Apr 12, 2024, 4:25:02 AMApr 12
to PIT Users
I would like to integrate Pitest in my pipeline which will fail if it does not reach 80% coverage.
The first time it should be run all test and after this it should be run only new added or modified code.
Is this approach feasible? how would it be done?
I have read that "withHistory" parameter it is more common to use it only in local executions and scmMutationCoverage not execute all code first time.

Thanks!



henry

unread,
Apr 12, 2024, 4:43:58 AMApr 12
to PIT Users
In theory this is possible using the history file mechanism. The details will be specific to how your pipeline is setup, and how your team merges in code, but the basic idea is to create an initial file from a full run, store it somewhere, then use it as the input file for the next analysis run. When new code is merged in, the file should be replaced with an updated file.

In practice, pitest's in built history mechanism doesn't do a great job when used in this fashion. The one provided by arcmutate fixes the various issues.


If your team is using pull requests, we would however recommend using the git integration instead of history files, as this usually provides much greater value. History files can then be used as a secondary mechanism to speed up the build as described in the posts below.


Henry

Ullrich Hafner

unread,
Apr 12, 2024, 5:29:11 AMApr 12
to pitu...@googlegroups.com
Where are you running your pipeline? GitLab, GitHub, Jenkins?

In Jenkins such a use case is part of the product. You can specify there in the pipeline that a build should be failed if
- the overall coverage decreased
- the overall coverage is below a threshold
- the pull request coverage is below the main branch coverage
- the pull request coverage is below the coverage of the changed files

Ulli 

--
You received this message because you are subscribed to the Google Groups "PIT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pitusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pitusers/9e427c2a-ea1b-4011-959b-22f81dc8372bn%40googlegroups.com.

Isabel Garcia

unread,
Apr 12, 2024, 7:00:39 AMApr 12
to PIT Users
Hello!
Thanks a lot for your response.
I am using Azure pipeline and I would like execute the test in Build Step. 
We can´t use  arcmutate owing to licence....
I am triying to publish the report in a resource folder(no tmp folder) in order to be read and replace it for next execution, and I am using this parameters in pom.xml

<historyInputFile>${project.basedir}/../resources/pitest.history</historyInputFile>
<historyOutputFile>${project.basedir}/../resources/pitest.history</historyOutputFile>


My question now is, if I execute "mvn -DwithHistory test-compile org.pitest:pitest-maven:mutationCoverage"
PIT will be able to read the report from new path configured and scan only new/modify code added?

Thanks a lot for your response!


henry

unread,
Apr 12, 2024, 7:05:36 AMApr 12
to PIT Users
The hard part of this is avoiding repeated full mutation analysis, not breaking the build based on a change in coverage.

henry

unread,
Apr 12, 2024, 7:23:58 AMApr 12
to PIT Users
If you store the files in a location that persists between runs, this will work (in that the cost of each analysis after the first one will be reduced). I'm not clear how/if your proposal persists the files between runs.
Reply all
Reply to author
Forward
0 new messages