Best Java Testing Techniques

I have several unit tests and component tests that I would like to test against several versions of Java (1.6, 1.7, 1.8, etc.).

I wonder what his best methodology is?

Do I have to run tests several times using Jenkins and every time I change the path of the JAVA_HOME variable to another JRE?

Can I use the Maven plugin? Maybe different profiles?

Also, is there a way to use TestNG to exclude tests based on the JRE version? I can handle this using the if statement in the java.version system property, however, I wonder if the style is more elegant.

In case this affects the answer, I would like to mention that, looking to the future, I would like to test it against several types of OS and several versions of the product (the same tests against v1.0, v2.0, etc. )

+8
java unit-testing integration-testing testng automated-tests
source share
3 answers

To run the same code under different conditions, jenkins can simply run the same scripts with different JAVA_HOME settings or different settings. Doing this on different triggers or as part of a single multi-step job is the solution for you.

Regarding TestNG, see this answer How to disable testng test based on condition

+6
source share

A possible approach is to use maven profiles in conjunction with the maven toolchains plugin .

In this approach, you configure several JDKs on your build server and configure your pom xml to have different profiles that run unit tests with each JDK.

You might want to consider testing not only different versions of Java, but also different versions of the target class; it can also be combined with the approach to the profile, having different profiles with different compilation settings.

last, the exclusion of mandatory fire tests can also be made from profiles, which also allows you to control this.

0
source share

I know one of the methodologies used in many open source projects that use TravisCI. In these projects, the .travis.yml file (the metadata file for TravisCI) contains this information. Example: -

 jdk: - oraclejdk7 - oraclejdk8 - openjdk6 - openjdk7 

I also used it in one of my open source projects ( see here ). I don’t know if there is any other optimized process in the industry, but it can be something open and can vary from organizations to organizations and projects to projects.

0
source share

All Articles