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

Run tests only for source code changed on CI build server #1148

Closed
prasad-1210 opened this issue Apr 21, 2021 · 3 comments
Closed

Run tests only for source code changed on CI build server #1148

prasad-1210 opened this issue Apr 21, 2021 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@prasad-1210
Copy link

Hello,

I've a Dotnet core project with XUnit test cases. Its taking almost 1 hour to run tests. Is it possible to run tests by detecting changes in source code since last test or only source code changes on current branch?

Please point me to right project if this is not right place.

Thanks in advance.

@prasad-1210 prasad-1210 changed the title Test only changes on build server Run tests only for source code changed on CI build server Apr 21, 2021
@petli
Copy link
Collaborator

petli commented Apr 21, 2021

In general, it is difficult to do this with any precision. Even if you have per-test code coverage and thus can see which current lines affect a specific test, you can't say for sure which tests any added lines might affect. (coverlet does not record which unit tests caused what code coverage, currently.)

I think the best you can hope for is to identify which unit test projects you need to re-run, based on which of their referenced projects have had changes. If you have a fine-grained project structure, this could reduce test time in some cases. Coverlet can't help with this approach, but perhaps you can identify that by what dotnet decides to rebuild. Something like this:

  • Check out the base version of the code (the previous commit, or the base commit for the branch, depending on your CI needs)
  • Build it
  • Check out the new commit
  • Record the current time
  • Build again
  • Only run the unit test projects where the DLL timestamps are newer than the recorded time before the build.

@MarcoRossignoli MarcoRossignoli added the duplicate This issue or pull request already exists label May 4, 2021
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented May 4, 2021

This is a duplicate of #973

We did an offline discussion and I've suggested for now to try to fork coverlet core to try to understand if using collectors(they have start/stop test event) and coverage check on the fly(you can understand what that test touched looking at "in memory hits" collection+source mappings) would be possible have an "incremental" test profile and run only test that will cover updated part since last test run. But at the moment this feature is out of coverlet scope, anyway I admit that I think it would be doable.

@MarcoRossignoli
Copy link
Collaborator

Closing because answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants