Allure TestOps Integration with XCTest framework

Integration with XCTest framework

This section will provide you information needed to integrate XCTest framework with allure TestOps.

Prerequisites

You need to download the latest version of CL integration utility from github.

Actions to be performed

  1. Run your tests
    • As the outcome you will have a directory (or folder if you like) with the tests results - Test.xcresults.
  2. Run following command for the integration utility you downloaded in Prerequisites section.
    xcresults export /path/to/Test.xcresult /path/to/allure-results
  1. In the directory (folder) allure-results you will have your tests results in the format consumable by Allure TestOps.
  2. Now, send the tests results to Allure TestOps either with the help of plug-in or using CLI utility allurectl.

Adding more information to the test results

The directory allure-results contains the tests results which you can find using following mask - *-results.json.

Tests results files generally have following structure:


{
  "name": "Creating new issue authorized user",
  "status": "passed",
  "stage": "finished",
  "description": "",
  "steps": [
    {
      "name": "Starting web driver",
      ...
    }
  ],
  "attachments": [],
  "parameters": [],
  "start": 1609143700594,
  "stop": 1609143701648,
  "fullName": "io.eroshenkoam.allure.IssuesWebTest.shouldCreateIssue",
  "labels": [
    {
      "name": "tag",
      "value": "web"
    }, 
    ...
  ],
  "links": []
}

For us, the labels section is of most interest at the moment. In this section the information is provided as key-value pair. Using this, we can supply any information to Allure TestOps.

Adding information to this section is as follows:

  1. Add new label to the test results as described here
  "labels": [
    {
      "name": "label-name",
      "value": "label-value"
    }, 
  ]
  1. Jump to the setting of a project to appropriate section (Custom Fields, Environment, Members, Issues, etc.) and add the mapping.

if you see this, please file a support ticket to https://support.qameta.io

  1. After you performed the mapping you will see a new field called Component with value from label-value.
  2. Use the same approach to supply the information about Environment, Members, Issues etc.

Adding label to XCTest

To add a label to XCTest you need to log the Activity using XCTContext.runActivity.By default such activities are shown as steps of an automated test.

If the activity fits to Allure’s template allure.label.<name>:<value>, then it will be excluded form the steps of the automated test and will be used as a label.

To make it simple, you can use following code as helper in your automated test:

extension XCTest {

func id(_value: String) {
    label(name: "AS_ID", values: value)
}

func epic(_ values: String...) {
    label(name: "epic", values: values)
}

func feature(_ values: String...) {
    label(name: "feature", values: values)
}

func story(_ stories: String...) {
    label(name: "story", values: stories)
}

func label(_ name: String,_ values: [String]) {
    label(name: name, values: values)
}

func step(_ name: String, step: () -> Void) {
    XCTContext.runActivity(named: name) { _ in
        step()
    }
}

private func label(name: String, values: [String]) {
    for value in values {
        XCTContext.runActivity(named: "allure.label." + name + ":" + value, block: {_ in})
    }
}

}

The following Examples section will show you how to use the helpers from above.

Examples

Assumption: you are using the helpers example from above.

Assigning the id to automated test to integrate with manual testing

func testPoppingAViewController() {
        id("777")
        step("Verify Volleyball exists") {
            XCTAssert(app.navigationBars["Volleyball?"].exists)
        }
        ...
    }
}

Adding a feature to automated test

func testPoppingAViewController() {
        feature("New Feature")
        step("Verify Volleyball exists") {
            XCTAssert(app.navigationBars["Volleyball?"].exists)
        }
        ...
    }
}

Adding the environment to automated test

  1. Add the label to test results

    func testPoppingAViewController() {
            label("stage", "testing")
            step("Verify Volleyball exists") {
                XCTAssert(app.navigationBars["Volleyball?"].exists)
            }
            ...
        }
    }
    
  2. Add the mapping to the environment variable

if you see this, please file a support ticket to https://support.qameta.io

Adding a custom field to automated test

  1. Add the label to the test results

    func testPoppingAViewController() {
            label("component", "Database")
            step("Verify Volleyball exists") {
                XCTAssert(app.navigationBars["Volleyball?"].exists)
            }
            ...
        }
    }
    
  2. Add the mapping to the environment variable

if you see this, please file a support ticket to https://support.qameta.io

Back to frameworks page