From 591a5a930f497bb04cd1d837209154e8aafe4735 Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Mon, 16 Dec 2024 18:52:41 +0100 Subject: [PATCH 1/3] explain how to adjust the home directory --- content/doc/developer/testing/index.adoc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/content/doc/developer/testing/index.adoc b/content/doc/developer/testing/index.adoc index 0c0cd0abc20c..30c1b29d1498 100644 --- a/content/doc/developer/testing/index.adoc +++ b/content/doc/developer/testing/index.adoc @@ -367,7 +367,19 @@ report.copyFrom(getClass().getResourceAsStream("lint-results_r20.xml")); ---- ==== Customizing the `JENKINS_HOME` Directory -TODO: Write this section. + +If you want to adjust the `JENKINS_HOME` within a test, you can make use of the `JenkinsRule`-methods `withExistingHome()` or `withNewHome()`. +Let's assume in the directory "src/test/resources/home" everything is prepared for a good test suite, and you want to use that. +This can be achieved with the following example: + +[source,java] +---- + + @Rule + public JenkinsRule j = new JenkinsRule().withExistingHome(new File("src/test/resources/home")); +---- + +If you need a fresh `JENKINS_HOME` you can use `withNewHome()` which creates a fresh home, what the default of the `JenkinsRule()` at the beginning is. ==== Using `@LocalData` Runs a test case with a data set local to test method or the test class. This recipe allows your test case to start with the preset `JENKINS_HOME` data loaded either from your test method or from the test class. From 7b0137eb5a44473698fefb199df23ccc7e305ee7 Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Tue, 17 Dec 2024 08:07:23 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Mark Waite Co-authored-by: Kris Stern --- content/doc/developer/testing/index.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/doc/developer/testing/index.adoc b/content/doc/developer/testing/index.adoc index 01a6d40859f6..0b4e2511f3ab 100644 --- a/content/doc/developer/testing/index.adoc +++ b/content/doc/developer/testing/index.adoc @@ -368,8 +368,8 @@ report.copyFrom(getClass().getResourceAsStream("lint-results_r20.xml")); ==== Customizing the `JENKINS_HOME` Directory -If you want to adjust the `JENKINS_HOME` within a test, you can make use of the `JenkinsRule`-methods `withExistingHome()` or `withNewHome()`. -Let's assume in the directory "src/test/resources/home" everything is prepared for a good test suite, and you want to use that. +If you want to adjust the `JENKINS_HOME` within a test, use the `JenkinsRule`-methods link:https://javadoc.jenkins.io/component/jenkins-test-harness/org/jvnet/hudson/test/JenkinsRule.html#withExistingHome(java.io.File)[`withExistingHome()`] or link:https://javadoc.jenkins.io/component/jenkins-test-harness/org/jvnet/hudson/test/JenkinsRule.html#withNewHome()[`withNewHome()`]. +Let's assume in the directory "src/test/resources/home" everything is prepared for a good test suite, which you should use. This can be achieved with the following example: [source,java] @@ -379,7 +379,7 @@ This can be achieved with the following example: public JenkinsRule j = new JenkinsRule().withExistingHome(new File("src/test/resources/home")); ---- -If you need a fresh `JENKINS_HOME` you can use `withNewHome()` which creates a fresh home, what the default of the `JenkinsRule()` at the beginning is. +If you need a fresh `JENKINS_HOME` you can use `withNewHome()` which creates a fresh home, which is by default what the `JenkinsRule()` at the beginning is. ==== Using `@LocalData` Runs a test case with a data set local to test method or the test class. This recipe allows your test case to start with the preset `JENKINS_HOME` data loaded either from your test method or from the test class. From efaeb69d9d3b78538179fb41ea74646f2057ad4f Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Tue, 17 Dec 2024 20:02:04 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Kevin Martens <99040580+kmartens27@users.noreply.github.com> --- content/doc/developer/testing/index.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/doc/developer/testing/index.adoc b/content/doc/developer/testing/index.adoc index 0b4e2511f3ab..b470fe9f4bb8 100644 --- a/content/doc/developer/testing/index.adoc +++ b/content/doc/developer/testing/index.adoc @@ -369,7 +369,7 @@ report.copyFrom(getClass().getResourceAsStream("lint-results_r20.xml")); ==== Customizing the `JENKINS_HOME` Directory If you want to adjust the `JENKINS_HOME` within a test, use the `JenkinsRule`-methods link:https://javadoc.jenkins.io/component/jenkins-test-harness/org/jvnet/hudson/test/JenkinsRule.html#withExistingHome(java.io.File)[`withExistingHome()`] or link:https://javadoc.jenkins.io/component/jenkins-test-harness/org/jvnet/hudson/test/JenkinsRule.html#withNewHome()[`withNewHome()`]. -Let's assume in the directory "src/test/resources/home" everything is prepared for a good test suite, which you should use. +Let's assume everything in the directory "src/test/resources/home" is prepared for a good test suite, which you should use. This can be achieved with the following example: [source,java] @@ -379,7 +379,7 @@ This can be achieved with the following example: public JenkinsRule j = new JenkinsRule().withExistingHome(new File("src/test/resources/home")); ---- -If you need a fresh `JENKINS_HOME` you can use `withNewHome()` which creates a fresh home, which is by default what the `JenkinsRule()` at the beginning is. +If you need a fresh `JENKINS_HOME`, you can use `withNewHome()` to create a fresh home, which `JenkinsRule()` at the beginning defaults to. ==== Using `@LocalData` Runs a test case with a data set local to test method or the test class. This recipe allows your test case to start with the preset `JENKINS_HOME` data loaded either from your test method or from the test class.