How does Karate start up application in Azure pipeline? - spring

I have followed How to Run Karate API tests on Azure pipelines to set up karate on azure pipeline.
We need to first start up the application in order to run karate tests.
Imagine I have a dev api publicly available and I have some new changes to merge in.
It still doesn’t make sense to test on this dev environment because the new karate test cases on the new features are not yet available on dev and of course the karate tests will fail.
If we look at example projects they all excluded the karate test files. What is the reason to exclude them? Shouldn't we include them instead so the karate test run during pipeline?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<excludes>
<exclude>karate/**/*.java</exclude>
</excludes>
<includes>
<include>com/**/*.java</include>
</includes>
</configuration>
</plugin>

you can use maven command in azure to run karate test as I understood your requirement correctly.
But if you need to different steps for building application and running test, you need to have two step in the pipeline in order, like creating bash script or something similar. Maybe you can use Makefile and make command to build and run your test, like;
build-and-run:
mvn (run app command) && mvn clean test -Dtest=myRunner
Currently I am using azure devops for running some karate tests but my tests doesn't required to have make application since they are run against staging env. I used this step for running karate test:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean test -Dusername=$(USERNAME) -Dpassword=$(PASSWORD)'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
This is autogenerated by azure devops, I just put my run command

Well.. none of you were able to mention the maven failsafe plugin which were designed to run integration test.
First start up the enviornment with spring-boot-maven-plugin
This will start up your spring application in the azure hosted agent to run the karate test.
Karete documentation did a good job explaining how to change the enviornment in karate config.js. But didn't mention about what enviornment we should use in pipeline
It would still be localhost- to the virtual machine starting your spring application in pipeline

Related

How to skip cucumber tests during build & deployment when unit test runs but after deployment it should run cucumber tests via Jenkins - Maven

I have a build project in which i implemented Cucumber BDD and wrote features file and test classes. Now, what i want is that during build & deployment in Jenkins pipeline, all Unit tests should get executed but not the Cucumber tests i.e. Integration tests. As soon as deployment is completed then these cucumber tests should get executed. How we can achieve that?
Is there any way to skip cucumber test during the deployment but after the deployment completion it should execute them?
You can tag your tests with annotations as #Deploy and #AfterDeploy,
To maven deployment script, you can add following script :
-Dcucumber.options="--tags #Deploy"
For the tests after deployment you can use following :
-Dcucumber.options="--tags #AfterDeploy"

Deploying AEM projects using Maven

We are new to Adobe and going to start working with it. Our Build Tool is maven, CI tool- Jenkins. As we are using Maven as a build tool. How to deploy our artifacts to jetty web server?
In short, Can we deploy artifacts of adobe project using maven? or do we need to have plugins for jenkins to deploy artifacts to different environment. I have came across
Maven-jetty and cargo plugin for deployments using maven to jetty webserver.
If you want to deploy your project with Maven I suggest that you use the content-package-maven-plugin. You can read more about the details in Adobes official documentation. The basic principal is the following:
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.5.24</version>
<configuration>
<userId>admin</userId>
<password>admin</password>
<targetURL>http://localhost:4502/crx/packmgr/service.jsp</targetURL>
</configuration>
</plugin>
This is a simple example that would deploy to a default AEM installation on your local machine (or same machine as mvn runs).
If you are running your build on Jenkins you might want to consider not using Maven to deploy your artifacts. Usually, you have multiple AEM instances running to which you want to deploy your content packages: "author" and "publish".
For the builds running on Jenkins I would suggest deploying your artifacts using curl. I wrote an answer about uploading and installing content packages using curl on Stack Overflow: How to install large (content) packages in AEM.
I would strongly suggest you to use the Aem maven archetype to create your project. It will come with the default settings, POM entries so that you can change your configuration to deploy it to the required environments.
Here is the link -
https://github.com/Adobe-Marketing-Cloud/aem-project-archetype

Configure cucumber in TeamCity to run unit tests only using tags (Maven)

I have both unit and acceptance tests in a maven project (spring boot). I would like to run unit tests only when my build runs in TeamCity. I am using cucumber.
When i run the tests via command line, everything works as expected (only unit tests are run)
c:\apache-maven-3.3.9\bin\mvn package -Dcucumber.options="--tags #unit"
However, in teamcity, all tests are being run (unit and acceptance). It seems teamcity ignores my cucumber.options
In addition, when I double click on the 'test' lifecycle in Intellij, all tests are run as well (not just unit tests) So my guess is that TeamCity is doing exactly what the 'test' lifecycle does.
How can i get around this problem (in TeamCity)?. I have tried using a 'Command line' step, which works, however, i lose all the tests reporting as well as test coverage reports.
i have solved the Intellij problem by creating (or changing) a configuration:
Try writing it this way in TeamCity:
"-Dcucumber.options= --tags #unit"

JaCoCo with microservice project architecture?

My project consists of 6 microservices in java and I am trying to figure out how to merge the html reports from Jacoco into one overall coverage report. As it stands now I end up with a report for each service and it would be nice to have an aggregated one so I can more easily put it into our CI for visibility etc.
I've tried various things I've found on web searches, but I end up with an empty coverage file when I try those suggestions.
Here is my gradle file:
subprojects {
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7+"
reportsDir = file("$buildDir/reports/customJacocoReportDir")
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.destination "$buildDir/reports/jacocoHtml"
}
}
test {
finalized by jacocoTestReport
...
}
I run gradle test to run the tests and get the report output per service using the above, but I am really stumped on how to merge them into a single html report. If anyone has done this successfully please let me know. Thank you.
At the moment we have the same kind of problem, the jacoco agent has a maven goal called "merge". You can specify the source files and run it:
jacoco:merge
Full name:
org.jacoco:jacoco-maven-plugin:0.7.8-SNAPSHOT:merge
Description:
Mojo for merging a set of execution data files (*.exec) into a single file
Attributes:
Requires a Maven project to be executed.
The goal is thread-safe and supports parallel builds.
Since version: 0.6.4.
Binds by default to the lifecycle phase: generate-resources.
<fileSets>
<fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
Actual link: http://www.eclemma.org/jacoco/trunk/doc/merge-mojo.html
Hope it helps :D
I use jacoco:report-aggregate goal for this purpose.
According its documentation, I have a special module which is created just to run jacoco aggregation (it executes jacoco:report-aggregate during the "package" phase). It depends on modules whose test coverage I want to combine into a single report. This is also described by techgobi.blogspot.com.
As of version 0.8.8 of jacoco-maven-plugin, it has non-obvious peculiarity:
it works only if unit tests are executed by the same command as "jacoco:report-aggregate" goal.
In other words, if I use command-line to run unit tests from module A, and then I execute another command to run unit tests from module B, and then I execute "package" in the special module to trigger "jacoco:report-aggregate" - it won't work, JaCoCo will generate an empty aggregated report. In another scenario, it won't be empty, but the aggregated coverage will be 0%. It works only if unit test are executed by same command.

How Do I Properly Deploy With An Integration Test Project?

My projects are structured as:
root
common
client
server
test
server and client depend on common. test is a project that contains integration tests and these tests depend on client common and server.
If I add all of these as modules to root, then when I execute mvn deploy on root it will deploy the jars, and then run the integration tests. I only want to hit the deploy phase if my integration tests run successfully.
Is this possible with Maven?
You shouldn't run mvn deploy directly but use the release plugin instead. You have to run
mvn release:prepare release:perform
for doing and deplying a relase. See also this blog post about deploying snapshots.

Resources