Skip to content

Commit

Permalink
add section about operating system specific tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSpieker committed Dec 15, 2024
1 parent a3108f7 commit 2f7c856
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions content/doc/developer/testing/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,48 @@ To recreate the same configuration from a test method, you can do the following:
In order to test parts of your plugin, you may want certain files to exist in the build workspace, or that Jenkins is configured in a certain way.
This section covers various ways to achieve this using the Jenkins Test Harness.

=== Operating System Awareness

Sometimes it ios necessary to adjust the testcase depending on the operating system.
This can be the choice of Batch or Shell commands.
The following example shows how to make use of `Functions.isWindows()` to create different code depending on the operating system:

[source,java]
----
import hudson.Functions;
import hudson.model.FreeStyleProject;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import org.jvnet.hudson.test.JenkinsRule;
import org.junit.Rule;
import org.junit.Test;
public class MyPluginTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Test
public void testOnAllSystems() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
if(Functions.isWindows()) {
project.getBuildersList().add(new BatchFile("echo ahoy > log.log"));
} else {
project.getBuildersList().add(new Shell("echo ahoy > log.log"));
}
j.buildAndAssertSuccess(project);
}
}
----

If you just want to disable a test on Windows systems you can make use of `assumeFalse()` in combination with `Functions.isWindows()`:

`assumeFalse("TODO: Implement this test on Windows", Functions.isWindows());`

The following Test will only be executed if it is not executed under windows.

Be aware, that in general, we encourage to also test functionality under windows!

==== Customizing the Build Workspace


Expand Down

0 comments on commit 2f7c856

Please sign in to comment.