Selenium Java and Maven generate test jars without running the tests - selenium

I'm using Azure DevOps for CI/CD and for CI portion, I want to package the entire project and the CD portion will execute the tests from the jars
I can't seem to generate the executables though. I am using PageObject model so my layout for my maven project is as such
---src/main/java
-------PageObject
---src/test/java
------>tests here
My goal in Azure DevOps is to make sure the code compiles and package up the tests and drop them into an artifact. The release will then run the tests from this artifact. I don't want to drop the entire repo into the artifact, rather just the binaries (so whatever is in the ~/target/ folder.
It seems that when I try to compile, there are not any jars that are created.
I do not want the CI portion to execute the tests; simiply package up the artifact is my goal here.

Related

Does mvn clean install runs the surefire test before updating .m2 repository

How does mvn clean install works
mvn install should execute all the phases before install phase, that means it will first run the surefire test and then later update m2 respository with the dependency
Yes, this is how it works.
The phases are executed in order and the installation into the local repository is the last one.
With external dependencies it's simple: before compiling anything Maven downloads them.
With inter-module dependencies it's more complicated. It's important to understand that Maven first runs all phases for the 1st module, then runs all phases for the 2nd module, and so on. So depending on which phase you call there either will be a JAR file or there won't be.
Maven will try to give you as "high-quality" dependency as possible, meaning:
if you run mvn install - this will put 1st module's jar into ~/.m2, then by the time 2nd module starts - it already has a JAR dependency waiting in the local repo.
if you run mvn package the JAR doesn't go to local repo, it stays in target/. Thus this target/xxx.jar will be used as a dependency.
if you run mvn test there won't even be a JAR. There will only be target/classes. So 2nd module's compilation & runtime will have directory with classes & resources in its classpath (no JAR).
PS: this may actually lead to real implications. When you run tests in module2 you may be reading resources of module1 and working with their file paths. And everything will work fine in case of mvn test. But once you start running at least mvn package there won't be files anymore - all resources of module2 will be in JAR and thus can be accessed only with getResourceAsStream().

Jenkins Kubernetes plugin for Selenium - Maven pulls the dependencies but cannot compile

I've adapted the following example from the Jenkins Kubernetes plugin documentation
I've created a simple Jenkins pipeline job and added the groovy script in line. Maven pulls all the dependencies, but weirdly fails at the compilation step.
Here's the console output
How does one go about even debugging this as the failure happens on a temporary container?
The issue was with the settings.xml. It had a windows path which messed up maven's classpath. I added a line "sleep 99m" to keep the container on hold and then I SSH'd in to the container to debug to identify the root cause.

Run Integration test in toplevel pom

I have a project with 3 modules.I used maven as the build tool.I have Integration test module
Proj/mod1/pom.xml
Proj/mod2/pom.xml
Proj/intTest/pom.xml
Proj/pom.xml
Now I want to run the integration test using top level pom.xml,Is there a way to do that??
Thanxxx
Well, if I get it right the intTest-project does your integration tests and is part of your project Proj so if you run the module build with the appropriate phase (integration-test or verify, depending on what you use) this should be it ...

Configure a hudson maven job to keep building if there are test failures, but only deploy if there are no test failures

I've created a hudson job for our maven multi-project with 5 modules to deploy the SNAPSHOT artifacts to the maven repository. That's ok, as long as it builds successfully without test failures. However, now I'd like to fulfill the following requirements:
When a module has a test failure, the build should continue bulding and test the other modules, but turn yellow. Using -Dmaven.test.failure.ignore=true accomplishes, but fails at the next requirement.
When a module has a test failure, none of the artifacts should be deployed to the maven repository. Other projects depend on the snapshots this project and those projects only want to use the latest snapshots that don't have any failing tests.
Preferably, use the hudson maven integration instead of a free script we get the hudson report pages (red/yellow/blue status per module, build log error coloring, ...). Specifically running the maven build twice (first mvn test -Dmaven.test.failure.ignore=true, than mvn deploy -DskipTests) is not a solution because it's a performance loss and it confuses the hudson report pages and it's not atomic (it updates from the repositories again in the second build).
Is there any way to accomplish this?
There is an post build option called Deploy artifacts to Maven repository. If you do not select Deploy even if the build is unstable, then that mean if test fails, it won't deploy anything. Together with the -fae in the command, thing should work in your desired way
maybe you can try use mvn -fae option with you jobs on hudson - it make maven fail only after full build
If build time isn't a problem for you, I think the better option is to create another job, just for deploying. Something like this:
Configure your original job (let's call it "build job") with "mvn -fae clean install"
Create a new job ("deploy job") with "mvn deploy", and don't configure any Build triggers for it
In the "build job", enable the Build other projects option, under Post-build actions and set it to run your "deploy job".
Maybe you can try to configure both jobs to use the same workspace, saving some time on the whole build/deploy process.
If you happen to use Artifactory as a repository manager, you can use the Hudson/Jenkins Artifactory plugin to deploy your artifacts. This plugin will only deploy your artifacts if all tests pass for all modules of a Maven build.

How can i run maven tests against a previous deployed artifact of the same artifact?

I have an artifact abc which has some tests. I have different versions of abc within my repository. I now want to be able to run the latest tests against the 'old build' of the project.
I tried to add the artifact itself to the test dependencies but this (of course) results in a cyclic reference error of the maven reactor when building the tests via:
mvn compiler:testCompile
mvn surefire:test
Is there any smart way to run tests against a previous old build/artifact?
Must i create a new pom.xml in which i define the solo test execution?
Or should i add a postfix to my current artifact when executing the tests? (This would avoid a cyclic reference error)
Separate the tests out into a separate module/project that depends on the classes it tests. Then create separate profiles where you change the dependency to be on older releases.
The problem I foresee with what you're trying to do is that the package phase comes after the test phase of the maven lifecycle. Which to me implies that maven runs unit tests against the compiled classes and not the physical jar file (generated in the package phase). You'll therefore have to replace the contents of the projects /target/classes folder with the classes in the "older" jar.