u123
u123

Reputation: 16287

Use external files based on os from junit test when building with hudson/jenkins?

In a maven project I have some junit tests where I need to refer to some runtime libraries (the birt runtime) when running the tests:

  @Before
  public void setup() {
    // init osgi/birt rte.
    BEngine.getEngine().init("C:\\birt-runtime-2_6_1\\ReportEngine\\");
  }

  @Test
  public void testname() {
       // run test that requires the initialization of the above rte.
  }

This works fine when running the tests locally from eclipse. My maven project is also build on a linux server running jenkins but currently I disable tests that requires the above runtime libs.

I am considering to copy the runtime libs to the server running hudson and see if I can get hudson to pick up the location of these files when the tests are executed on hudson.

But to do this I need to use the correct location of the rte in the tests.

Any suggestions for doing this? Eg using env variables that can both be understood on windows/linux?

Upvotes: 0

Views: 558

Answers (1)

Matthew Farwell
Matthew Farwell

Reputation: 61705

If the values will not change during the lifetime of the test run (i.e. the build), then use an environmental variable, and just set it as an option in the surefire plugin, systemPropertyVariables.

The correct way to do this for different environments is to use different profiles in maven.

You can have a default profile which includes the set of variables for windows, and another for the hudson.

EDIT: For running the tests correctly from within Eclipse, then simply you can have a default value for the variable

public String getRteLocation() {
    String s = System.getProperty("test.rte.location");
    return (s == null) ? "C:\\birt-runtime-2_6_1\\ReportEngine\\" : s;
}

@Before
public void setup() {
    // init osgi/birt rte.
    BEngine.getEngine().init(getRteLocation());
 }

or simply set the environment variable in the Run Configuration in Eclipse.

EDIT: Just a clarification, when I say environment variables, I mean the -D variables set from the java command line.

Upvotes: 2

Related Questions