简体   繁体   中英

Run Java Selenium tests in Azure DevOps release pipeline

I'm doing a POC for a Java project in an AzureDevops CI/CD pipeline. I created a Maven project that has Selenium tests (TestNG) that run against a demo website which is independent of my project. I want to run unit tests in the build pipeline and UI Selenium tests in the release pipeline.

The Visual Studio test task seems to be the building block that I need. I think you can differentiate between unit tests & UI tests using the 'Test files' field like **\unit*Test.dll, **\ui*Test. Unfortunately, this task is not available/compatible for Java projects.

I was able to run the Selenium tests with the Maven task and Surefire plugin during build but remember, I only want to run unit tests during build.

I actually was able to run the Selenium tests in the release pipeline via a workaround which was:

  • Copy the whole project to the artifacts directory of the release during build (copy files task).
  • Add a Maven task to the release pipeline
  • Trigger the Selenium tests in pom.xml

Normally, you would only copy artifacts to the artifact directory so I think doing that is a huge hack.

Another problem is that Maven will build the project during build and release which is wasteful. To dial back the waste, some savvy Maven configuration might help. I was thinking about skipping compilation and resolve dependencies during release, but I don't know where to find the Maven dependencies in the DevOps ecosystem.

Am I missing something or is AzureDevops maybe not supporting Java all that well?

I do follow a method for Maven selenium tests on Azure DevOps. What I do is, in the build pipeline I build my tests in such a way that it produces a jar with all the dependencies and test classes in it. I also use testng in my approach. Next I copy my build Artifact to Artifactory. This completes the build. Now during the release I download my Artifact from Artifactory and I check the environment where i want to run and I inject the right testng file by running java -jar myfile.jar testngIT.xml. This runs my tests faster and better.

You can try just adding a test task in your release pipeline just as in the build pipeline. And add a copy task in the build pipeline to copy the test codes and files to the build artifacts and publish it to release pipeline.

Below steps is just for reference(in classic view ). Hope it can be of some help.

1, Add copy file task in the build pipeline to copy the all test files and all the dependent setting files to the test folder in artifacts.

在此处输入图像描述

2, Publish artifacts to release pipeline

在此处输入图像描述

3, In the release pipeline, add the task to execute the tests just like the way you do in build pipeline

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM