{"id":15067388,"url":"https://github.com/rpau/junit4git","last_synced_at":"2025-04-10T14:12:27.511Z","repository":{"id":46191315,"uuid":"106329870","full_name":"rpau/junit4git","owner":"rpau","description":"Junit Extensions for Test Impact Analysis","archived":false,"fork":false,"pushed_at":"2023-02-07T10:26:44.000Z","size":270,"stargazers_count":44,"open_issues_count":11,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T12:56:19.070Z","etag":null,"topics":["git","incremental","junit","testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rpau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-09T20:06:32.000Z","updated_at":"2025-01-21T13:53:45.000Z","dependencies_parsed_at":"2024-09-29T11:44:32.052Z","dependency_job_id":"612d4260-6650-4494-81ff-8fdcdbed1acc","html_url":"https://github.com/rpau/junit4git","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpau%2Fjunit4git","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpau%2Fjunit4git/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpau%2Fjunit4git/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpau%2Fjunit4git/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rpau","download_url":"https://codeload.github.com/rpau/junit4git/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232618,"owners_count":21069487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","incremental","junit","testing"],"created_at":"2024-09-25T01:20:20.914Z","updated_at":"2025-04-10T14:12:27.485Z","avatar_url":"https://github.com/rpau.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](logo.png?raw=true\u0026v=4\u0026s=200)\n\n[![Build Status](https://travis-ci.org/rpau/junit4git.svg?branch=master)](https://travis-ci.org/rpau/junit4git)\n[![codecov](https://codecov.io/gh/rpau/junit4git/branch/master/graph/badge.svg)](https://codecov.io/gh/rpau/junit4git)\n\nThis is a JUnit extension that ignores those tests that are not related with \nyour last changes in your Git repository. This is not a new idea, since big companies, specially\nwith big mono-repos have worked on it.\n\n[Martin Fowler](https://martinfowler.com/articles/rise-test-impact-analysis.html) also describes how to use the test\nimpact to infer the minimum tests to run.\n\nYou can use it from Maven and Gradle projects in any Junit based\nproject (written in any JVM based language: e.g Kotlin, Java, Scala)\n\n## Getting Started\nThese instructions will get you a copy of the project up and running on your local machine.\n\n### Requirements\n\n- JRE 8\n- Git\n- Maven or Gradle\n- Master as a default base branch\n\n### 1. Configure your build\n\n#### 1.1 If you are using Maven\n\nDeclare a new test dependency in your `pom.xml`:\n```xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.walkmod\u003c/groupId\u003e\n    \u003cartifactId\u003ejunit4git\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n  \u003c/dependency\u003e\n```\nAdd/Edit also the `maven-surefire-plugin` adding the `listener` property:\n\n ```xml\n \u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n     \u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n     \u003cversion\u003e2.20.1\u003c/version\u003e\n     \u003cconfiguration\u003e\n       \u003cproperties\u003e\n         \u003cproperty\u003e\n           \u003cname\u003elistener\u003c/name\u003e\n           \u003cvalue\u003eorg.walkmod.junit4git.junit4.Junit4GitListener\u003c/value\u003e\n         \u003c/property\u003e\n       \u003c/properties\u003e\n     \u003c/configuration\u003e\n  \u003c/plugin\u003e\n ```\n\nCommit these changes into your `master` branch.\n\n```bash\ngit checkout master\ngit add pom.xml\ngit commit -m 'junit4git setup'\n```\n\n#### 1.2 If you are using Gradle\n\nIn this case, is preferable to use Junit5 because Gradle does not support to setup Junit listeners. \nHowever, there is a workaround for Junit4 and scalatest.\n\n##### 1.2.1 If you are using Junit4 \n\n- Modify your `build.gradle` file with the following\ncontents:\n\n```\n  testCompile(\"org.walkmod:junit4git:${version}\")\n```\n- Moreover, you need to setup a different runner for your tests. Therefore, you need to add\n `@RunWith(Junit4GitRunner.class)` in all your tests classes.\n \n- Setup the agent in your `build.gradle` file.\n\n```\nconfigurations {\n    agent\n}\n\ndependencies {\n  agent \"org.walkmod:junit4git-agent:${version}\"\n}\n\ntest.doFirst {\n    jvmArgs \"-javaagent:${configurations.agent.singleFile}\"\n}\n```\n\n##### 1.2.2 If you are using Junit5 \n\nModify your `build.gradle` file with the following\ncontents:\n\n```\n  testCompile(\"org.walkmod:junit5git:${version}\")\n```\nAnd then:\n\n```bash\ngit checkout master\ngit add pom.xml\ngit commit -m 'junit4git setup'\n```\n\n##### 1.2.3 If you are using Scalatest \n\n- Modify your `build.gradle` file with the following\ncontents:\n\n```\n  testCompile(\"org.walkmod:scalatest4git_2.11:${version}\")\n```\n- Moreover, you need to setup a different runner for your tests. Therefore, you need to add\n `@RunWith(classOf[ScalaGitRunner])` in all your tests classes.\n \n- Setup the agent in your `build.gradle` file.\n\n```\nconfigurations {\n    agent\n}\n\ndependencies {\n  agent \"org.walkmod:junit4git-agent:${version}\"\n}\n\ntest.doFirst {\n    jvmArgs \"-javaagent:${configurations.agent.singleFile}\"\n}\n```\n\n### 2. Generate a Test Impact Report\n\nAfter having configured your build, run your `master` branch tests. \n\n```bash\nmvn test -- or gradle check\n.\n.\n[WARNING] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0\n```\nA Test Impact Report is generated as a Git note at (`refs/notes/tests`). You can\ncheck the contents with:\n\n```bash\nexport GIT_NOTES_REF=refs/notes/tests\ngit notes show\n```\nA report, similar to the next one, will be printed in your console.\n\n```json\n[\n  {\n    \"test\": \"CalculatorTest\",\n    \"method\": \"testSum\",\n    \"classes\": [\n      \"Calculator\"\n     ]\n  }\n  ...\n]\n```\n\nThis report specifies classes that are instantiated for each one \nof your test methods.\n\n### 3. Run the Impacted Tests\n\nAfter generating your test impact report, run the tests again (from the master branch or in a new local branch)\n\n```bash\nmvn tests -- or gradle check\n.\n.\n[WARNING] Tests run: 0, Failures: 0, Errors: 0, Skipped: 4\n```\n\nVoilà! You will see that all the tests have been skipped because there is no change that may \naffect in our test results. \n\nHowever, if you add / modify \nnew test files or modify an existing source file, only the affected tests are executed.\n\n### 4. Use Travis to Upgrade the Test Impact Report\n\nTests can be run incrementally once the base testing report is generated. However, how can we \nmake them updated every time a pull request is merged?\n\nOur strategy consist of delegating this work to Travis with the following steps: \n\n- **Generate an OAuth token for your GitHub User**. Go to\n `Settings \u003e Developer Settings \u003e Personal access tokens`. Then `Generate new token`\n with `repo` permissions. Copy the generated token into the clipboard.\n- **Add a new Travis Environment Variable**. Go to your last build, and then:\n `More Options \u003e Settings \u003e Environment Variables`.\n Add an environment variable named `GITHUB_TOKEN` and paste the contents of your clipboad.\n- **Edit your `.travis.yml` file** adding the following contents:\n\n```yml\nbefore_install:\n  - echo -e \"machine github.com\\n  login $GITHUB_TOKEN\" \u003e\u003e ~/.netrc\nafter_script:\n  - git push origin refs/notes/tests:refs/notes/tests\n```\n- **Commit your `.travis.yml` changes** to master.\n\n## License\n\nThis project is licensed under The Apache Software License.\n\n## Build\n\nThis is a Gradle project that you can easily build running\n\n```bash\ngradle build customFatJar\n```\n\nOr, if you want to generate a version to test it from a Maven project\n\n```bash\ngradle publishToMavenLocal\n```\n\n## FAQs\n\n- The agent fails when Jacoco is Running.\n\nBy default, Jacoco is appending an agent before running tests. Jacoco agent needs \nto be disabled or added as first agent because it requires non-altered classes \nby other agents.\n\nTo disable jacoco:\n\n```\ntest.extensions.findByType(JacocoTaskExtension.class).enabled = false\n```\n\nTo setup as first agent: \nhttps://discuss.gradle.org/t/jacoco-gradle-adds-the-agent-last-to-jvm-args/7124/5\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpau%2Fjunit4git","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frpau%2Fjunit4git","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpau%2Fjunit4git/lists"}