0

I have the following code snippet in Java (run the project with Java 8 and apache-maven-3.6.3)

@ParameterizedTest
@ValueSource(strings = {"true"})
public void P34AMA_2837(String expected_result) throws Throwable {
Xray.setTestKey("P34AMA-2818"); 
assertEquals(expected_result, "true");         
}

This code snippet works locally in my machinethrough the cmd (C:\work\apps\apache-maven-3.6.3\bin\mvn test -Dbusiness_date="20230124" ), but the Jira/Xray test ID is not integrated in Jira/Xray using the Jenkins Xray-connector plugin and the following Jenkins pipeline

def SOURCE_SYSTEM;
pipeline {
   agent { label 'p34' }
   parameters {
        string(name: 'BUSINESS_DATE', defaultValue: '20230124', description: 'Choose a 
        BUSINESS_DATE')
    }
   stages {
      stage('Clean Workspace') {
         steps {
             cleanWs()
          }
      }
      stage('Clone Respository') {
         steps {
            script{
         
             if ("${params.JIRA_ID}"){
                     bat "echo ${params.JIRA_ID}"
                     withCredentials([
                     string(credentialsId: 'df54e5bb-3330-4201-b699-644e5a609c4d', variable: 
                      'TOKEN')]) {
                      bat "git -c http.sslVerify=false clone https://$TOKEN@bitbucket- 
                      mut.d.bbg/scm/p34actzmad/actimizemse-batch-java.git"
                         dir("${WORKSPACE}/actimizemse-batch-java"){
                         bat "echo %JAVA_HOME%"
                         bat "git checkout origin/tests" 

                    bat "C:/work/apps/apache-maven-3.6.3/bin/mvn test - 
                    Dbusiness_date=${params.BUSINESS_DATE} "
                    bat "echo ${params.BUSINESS_DATE}"
                 }
               } 
         } else {
         if ("${params.ENTITY}.isEmpty()") {
         echo 'No entities were chosen'
         if ("${params.JIRA_ID}.isEmpty()") {
         echo 'No jira_id were chosen'
         withCredentials([
                string(credentialsId: 'if54e5bb-3630-4209-b699-644e5a929c4v', variable: 'TOKEN')]) {
                 bat "git -c http.sslVerify=false clone https://$TOKEN@bitbucket-mut.d.bbg/scm/p34actzmad/actimizemse-batch-java.git"
                 dir("${WORKSPACE}/actimizemse-batch-java"){
                    bat "echo %JAVA_HOME%"
                    bat "git checkout origin/tests"
                    bat "C:/work/apps/apache-maven-3.6.3/bin/mvn test -Dbusiness_date=${params.BUSINESS_DATE} "
                    //bat "C:/work/apps/apache-maven-3.6.3/bin/mvn dependency:purge-local-repository -DactTransitively=false -U test -Dcurrency=\"EUR\""
                    //bat "echo %BUSINESS_DATE%"
                    bat "echo ${params.BUSINESS_DATE}"
                 }
                           
               } 
        } 
        }
        }
     }
     }
  }
     stage ('Import Results into Jira') {
        steps {
                step([$class: 'XrayImportBuilder',
                endpointName: '/junit',
                importFilePath: '*/reports/*.xml',
                projectKey: 'P34AMA',
                importToSameExecution: 'false',
                serverInstance: '3146a388-d399-4e35-ae28-8c65404d6f9d',
                credentialId:'58287529-194d-4e91-9964-7d740d8d2f65',
                fixVersion: 'MSE 3.3',
                inputInfoSwitcher: 'fileContent',
                inputTestInfoSwitcher: 'fileContent',
                testImportInfo: '''{
                  "fields": {
                    "labels": ["Quotes"],
                  }}'''
                ])
            }
        }  
   }}

I am in the "tests" branch both locally and in the Jenkins pipeline.

Additionally, the Test Executions used to be created in Jira/Xray with the @XrayTest annotation and correctly linked to the Jira Test ID (using xray-junit-extension) .But now, using zebrunner agent core 1.7.2 , the Test Executions are no longer linked to the correct Test IDs.

I really need this syntaxe, since I don't want to use annotations. If I overcome this technical issue I'd like to input an array of undefined strings (resulting from another java method) that provide the Test IDs. This is the reason why I am using Zebrunner, since annotations can not be iterated.

Code Klaudia
  • 47
  • 1
  • 7
  • Can you please elaborate your use case and the flow? You are using Xray and Zebrunner together? What are you using Zebrunner and its Zebrunner agent core for? And what's the role of Jenkins on that? – Sérgio Mar 15 '23 at 17:27
  • Also, at least to me was not totally clear what you had before and what you're now trying to accomplish. If you can clarify that, it would be great – Sérgio Mar 15 '23 at 17:44
  • I am using xray-junit-extension and Zebrunner agent core together to generate a .xml test report. With xray-junit-extension I can use this syntaxe "xrayReporter.addComment". With zebrunner agent core I can use this syntaxe : "Xray.setTestKey". These two syntaxes should generate a .xml test report with the results of each test, the respective comments and the Jira ID to which they'll be associated. Finally, Jenkins integrates this .xml into Jira/Xray creating test executions that are associated to the already existing tests. Previously, instead of Xray.setTestKey I had @XrayTest and it worked. – Code Klaudia Mar 16 '23 at 10:15
  • Understood, thanks. I don't know Zebrunner, and this seems to be a question about their API, so unfortunatelly can't help on that. If I may ask, any reason to not use xray-junit-extensions? – Sérgio Mar 16 '23 at 10:22
  • Currently I do not want to use the @XrayTest anymore. I would like to have this: @ ParameterizedTest @ MethodSource("provideMyObjects") public void test(String jira_test_id) throws Throwable { Xray.setTestKey(jira_test_id); assertEquals("true", "true"); } My goal is to have a method that returns a string array of Jira IDs (provideMyObjects()). Instead of performing a bunch of tests, I could have only ONE single test, that runs the same method with different parameters. And associate every single iteration of this test to a different Jira Test ID – Code Klaudia Mar 16 '23 at 10:31
  • The xray-junit-extension is awesome. But does not allow me to iterate different Jira IDs inside the @XrayTest annotation. I tryed to create my own annotation, and even tryed to re-write and override the plugin, but this turned out to be extremely difficult to me, even with the help of ChatGPT. – Code Klaudia Mar 16 '23 at 10:35
  • I would not recommend using the same test method to link it to different test cases. A test method should have a clear purpose and have abstract a well-defined test idea. If you aim to perform data-driven testing then it's another thing :) In data-driven you are exercising the same test idea but using different input parameters. I've added recently the support in xray-junit-extensions for Xray JSON reports, allowing you to report the results of a data-driven test; in this case it will create one Test in Xray along with the respective dataset attached to it.. but it will be just 1 Test. – Sérgio Mar 16 '23 at 10:43
  • Thank you a lot for your feedback @Sérgio. I am going to have a look :) – Code Klaudia Mar 16 '23 at 11:38

1 Answers1

1

@Code Klaudia, do you use Zebrunner Automation Reporting? Zebrunner agent core library has a lot of flexibilities and customizations to operate with x-ray but it has sense only in conjunction with Automation Reporting back-end which might export automation results into the x-ray. Details docs: https://zebrunner.com/documentation/reporting/carina-testng/#xray

Vad
  • 11
  • 1
  • 1
    I believe that in order to acquire the Zebrunner Automation Reporting in my Java project I would need to install these two dependencies in the pom.xml: com.zebrunner junit5-xray-plugin 1.0.0 com.zebrunner reporting 3.0.3 Do you think it would be possible to confirm me this? Thank you a lot! – Code Klaudia Mar 16 '23 at 14:48
  • 1
    No way to do it via dependencies:) That's proprietary paid solution to manage QA processes as much efficient as possible with a full control over the application quality and QA teams performance. Importing any open source Zebrunner modules without automation reporting or test case management doesn't have any sense. – Vad Mar 16 '23 at 15:55