When using gradle, I find I cannot have my testcases updated in Rally, as I would when using Maven. How would I do this? - gradle

When using gradle, I find I cannot have my testcases updated in Rally, as I would when using Maven. How would I do this?
Note: I'm using intelliJ as my IDE
In Maven I would use parameters similar to:
-DrallyIntegration=true
-DrallyEnabled=true
-DrallyUpdateStrategy=async
-DtestBuild=buildDetails_1
-DtestUserEmail=bob#mailinator.com
-DrallyKey=rallyKeyValue
-DtestSetId=TestSetName
-Drally.url=https://url_for_Rally.rallydev.com
But including these in a gradle run script (in run configurations) does not seem to be picked up on at all.

Thanks to y.bedrov for the answer.
For clarity , what I needed to do was add the block below to my build.gradle
(note - there are other things defined in the integrationTest task, but the systemProperties are what are needed to get rally integration working)
task integrationTest(type: Test) {
systemProperty "rallyIntegration", "true"
systemProperty "rallyEnabled", "true"
systemProperty "rallyUpdateStrategy", "async"
systemProperty "testUserEmail", "e124207#mastercard.com"
systemProperty "rallyKey", "_7G5umnREQpC98eDvHXkI38stUv7k0LjnZmaxSy4xxU"
systemProperty "rally.url", "https://rally1.rallydev.com"
systemProperty "testSetId", "TS102719"
}
Also, I included the rally plugin as a dependancy:
testImplementation('com.rallydev.rest:rally-rest-api:2.2.1')
After rebuilding, my test cases results were updated in Rally

Related

How can I create two separately configured bootRun tasks using Gradle?

I want to define two different versions of the bootRun task in a Spring boot application using Gradle. This is my attempt, which worked for customizing a single bootRun task. But with multiple tasks containing bootRun, the last bootRun overrides the previous ones.
task local {
bootRun {
systemProperty "spring.profiles.active", "dev,postgres"
jvmArgs "--add-opens=java.base/java.util=ALL-UNNAMED", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
}
}
local.finalizedBy bootRun
task prod {
bootRun {
systemProperty "spring.profiles.active", "postgres"
jvmArgs "--add-opens=java.base/java.util=ALL-UNNAMED"
}
}
prod.finalizedBy bootRun
Here, when I run ./gradlew :local, the spring profiles are only postgres. When I comment out the prod task, I get both dev,postgres as expected.
As currently written, your local and prod tasks are default tasks that aren't really doing anything. Your use of bootRun within their configuration is altering the configuration of the existing bootRun task that Spring Boot's Gradle plugin defines.
When you define the tasks, you need to tell Gradle that they are a BootRun task:
task local(type: org.springframework.boot.gradle.tasks.run.BootRun) {
// …
}
You also need to configure the main class name and the classpath of your new task. You probably want those to be the same as the default bootRun task:
task local(type: org.springframework.boot.gradle.tasks.run.BootRun) {
mainClass = bootRun.mainClass
classpath = bootRun.classpath
}
You can then customize the system properties and JVM arguments as you were before. Putting this all together, you can configure your local and prod tasks like this:
task local(type: org.springframework.boot.gradle.tasks.run.BootRun) {
mainClass = bootRun.mainClass
classpath = bootRun.classpath
systemProperty "spring.profiles.active", "dev,postgres"
jvmArgs "--add-opens=java.base/java.util=ALL-UNNAMED", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
}
task prod(type: org.springframework.boot.gradle.tasks.run.BootRun) {
mainClass = bootRun.mainClass
classpath = bootRun.classpath
systemProperty "spring.profiles.active", "postgres"
jvmArgs "--add-opens=java.base/java.util=ALL-UNNAMED"
}

Getting jacoco code coverage at the same as running tests

I have jacoco set up for my project.
I can do:
gradle cleanTest test
followed by
gradle jacocoTestReport
and get code coverage
This means two steps. Is there any way, I can just pass a switch to gradle test and get it
https://docs.gradle.org/current/userguide/jacoco_plugin.html
If the Java plugin is also applied to your project, a new task named
jacocoTestReport is created that depends on the test task.
So just call gradle jacocoTestReport, the test will also be invoked first.
edit : if you really want to call the test task, just add this in your build.gradle :
test.finalizedBy jacocoTestReport

Specifying xmlpathinjar TestNG option with Gradle test task

Is it possible to run a TestNG test suite that is embedded in a JAR file via a Gradle test task?
My project includes JARed bundles of TestNG tests that have an embedded testng.xml file defining which tests should be run in the JAR. Is it possible for Gradle to refer to this embedded XML when running the TestNG tests?
From the command line I use the xmlpathinjar option.
I dont think it can be done using the Gradle TestNG task. I couldn't find any such support in the TestNGOptions
Instead of using
test{
useTestNG()
}
you could try going through this post on SO How can I tell Gradle to use my testng.xml file for Test Classes and Ordering? and maybe employ the approach detailed here https://stackoverflow.com/a/28868416
But when you are using a custom Gradle task to run your TestNG tests, please make sure that you add a reference to the ExitCodeListener
Here's a sample
task ('myTask', type: JavaExec) {
main = 'org.testng.TestNG'
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
args = ["-xmlpathinjar", "suites/mysuite.xml", "-listener", "org.testng.TestNG\$ExitCodeListener"]
}
More details on why the ExitCodeListener needs to be referred, can be found here

gradle bootRun > Use test classpath

The problem I was having, was that I wanted to include test classpath resources in SpringBoot's bootRun gradle task. Why? So that I could use a test profile with test resources, to mock integration points.
What I tried:
The spring boot documentation only offers the addResources = true option (I tried using customConfiguration as per the similar bootRepackage configuration, to no avail)
No additional options are visible by looking at the BootRunTask source code
The equivalent maven plugin has a plethora of options, including useTestClasspath (which isn't mirrored in the gradle version)
I came across the following solution, which solved this issue for me.
Basically, the BootRunTask extends the standard JavaExec task, which offers a classpath option. So, you can add the test classpath resources by using the following gradle configuration:
bootRun {
classpath = sourceSets.test.runtimeClasspath
}

How to exclude a sub-project with gradle cobertura plugin

We are using gradle-cobertura-plugin, and have a main project with lots of subprojects, but have to exclude cobertura for some subprojects. Tried using the following:
project('test-modules:functional-tests') {
cobertura {
skip = true
}
}
But gradle complains that
Deprecated dynamic property: "skip" on "net.saliman.gradle.plugin.cobertura.CoberturaExtension_Decorated#6e56dd10", value: "true"
What is the way to skip this subproject?
Thanks,
Paddy
the coberbura configuration does not know any skip flag, so you're introducing a new property here, this is what the deprecation warning tries to tell you. I don't know the details about the Cobertura plugin, but you can disable the cobertura task by setting enabled=false
coberturaTask.enabled = false // you have to replace 'coberturaTask' with the correct task name here
cheers,
René

Resources