Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

💬 EN

#


Why is the “Associate Test Case” button missing from my Azure Pipelines test results tab? The “Bug” and “Link” buttons exist, but “Associate Test Case” is completely missing, even though the docs say it should exist

The “Associate Test Case” button is missing from your Azure Pipelines test results tab likely because you are using automated tests that are not directly supported for association with test cases through the Azure DevOps interface. This issue is common when using non-Microsoft testing frameworks or when tests are not run through Visual Studio12.

To address this issue, you have a few options:

  1. Use Visual Studio for test association: If possible, run your tests through Visual Studio Enterprise or Professional 2017 or later. This allows you to associate automated tests with test cases directly from the Test Explorer window3.
  2. Use the Azure DevOps REST API: You can programmatically associate test results with test cases using the Azure DevOps REST API. However, this method can be complex and may require additional development effort2.
  3. Manual association: After test results are published, you may need to manually associate them with test cases through the Azure DevOps web interface.
  4. Consider using supported test frameworks: Microsoft-supported test frameworks like MSTest, NUnit, or xUnit may provide better integration with Azure DevOps for test case association13.

If you’re using a non-Microsoft test framework like pytest, automatic association through the UI is not directly supported2. In such cases, you may need to explore custom solutions or use the API to link test results to test cases.

Remember that the ability to associate test results with test cases depends on various factors, including the test framework, how tests are executed, and how results are published to Azure DevOps43.


#3 is where the docs say that button should exist.

I apologize for the confusion in my previous response. You’re correct that the “Associate Test Case” button should be available for manual association according to the Microsoft documentation. If this button is missing from your Azure Pipelines test results tab, there could be a few reasons for this:

  1. Permissions issue: Ensure you have the necessary permissions to associate test cases. You typically need “Edit test results” permissions for the project.
  2. Test run configuration: The test run might not be configured correctly to allow for test case association. Check if the test run is set up to enable this feature.
  3. Azure DevOps version: Confirm you’re using a version of Azure DevOps that supports this feature. The “Associate Test Case” button might not be available in older versions.
  4. UI bug or caching issue: There could be a UI bug or a caching issue in your browser. Try clearing your browser cache or using a different browser to see if the button appears.
  5. Feature flag: Microsoft sometimes uses feature flags to roll out new features gradually. It’s possible this feature is not enabled for your organization yet.

If none of these solve the issue, I recommend:

  1. Contacting Azure DevOps support directly, as this appears to be a discrepancy between the documented functionality and what you’re experiencing.
  2. Checking the Azure DevOps Developer Community forum to see if others have reported similar issues.
  3. Considering filing a bug report if you believe this is indeed a bug in the Azure DevOps platform.

Elaborate on the test run configuration suggestion (#2), please

To elaborate on the test run configuration suggestion, there are a few key points to consider:

  1. Test run settings: Ensure that your test run is configured to allow for test case association. This setting might be found in the test run configuration or in the pipeline settings5.
  2. Visual Studio Test task configuration: If you’re using the Visual Studio Test task in your Azure Pipelines, make sure it’s set up correctly. The task should be configured to use the test plan or test suite that contains your test cases5.
  3. Test method attributes: In your test code, use appropriate attributes to link tests to test cases. For example, you can use the TestCaseId attribute from the TestCaseAttributes NuGet package to specify the Azure DevOps test case ID directly in your code6.
  4. Pipeline configuration: In your build pipeline YAML, include the TestCaseAssociation task. This task is responsible for populating the “Automation” fields attached to Azure DevOps test case work items6.
  5. Dry Run flag: When configuring the TestCaseAssociation task, consider using the Dry Run flag in your PR build pipeline. This allows you to verify the associations without actually updating the test cases6.
  6. Release pipeline: Create a release pipeline that executes tests via the test plan. This ensures that your associated automated tests are run as part of your release process6.
  7. Test Explorer in Visual Studio: If you’re using Visual Studio 2017 or later, you can associate tests directly from the Test Explorer window. This method allows you to manually link test methods to specific test cases7.

By carefully configuring these aspects of your test run and pipeline setup, you should be able to enable the test case association feature and see the “Associate Test Case” button in your Azure Pipelines test results tab.


How about me not being able to flip the value of a Test Case field called “Microsoft.VSTS.TCM.AutomationStatus” from “Not Automated” to “Automated” because the API complains that “Automated” is not in the list of supported values? Even though it totally is, in the docs?

The issue you’re experiencing with the “Microsoft.VSTS.TCM.AutomationStatus” field is a known limitation of the Azure DevOps API. Despite what the documentation might suggest, setting the status to “Automated” via the API is not directly supported8.

The reason for this limitation is that the “Automated” status is unique and requires more than just changing a field value. To set a test case as “Automated”, it needs to have an associated automated test8.

Here are some key points to understand:

  1. API Limitation: The API doesn’t allow directly setting the status to “Automated” because this status requires an actual test association8.
  2. Visual Studio Requirement: To associate a test with a test case and set it as “Automated”, you typically need to use Visual Studio8.
  3. Workaround: Instead of directly setting the “Automated” status, you can update related fields that will indirectly change the automation status:
    • Update Microsoft.VSTS.TCM.AutomatedTestId
    • Update Microsoft.VSTS.TCM.AutomatedTestStorage
    • Update Microsoft.VSTS.TCM.AutomatedTestName

When these fields are properly set, Azure DevOps will automatically update the automation status to “Automated”8.

  1. API Versions: This behavior is consistent across different API versions, including the latest ones as of March 20259.

To resolve this issue, you have a few options:

  1. Use Visual Studio to associate the automated test with the test case.
  2. Implement the workaround by updating the related fields mentioned above through the API.
  3. If possible, consider using Microsoft-supported test frameworks like MSTest, NUnit, or xUnit for better integration with Azure DevOps.

Remember that while the API might not directly support setting the status to “Automated”, it’s still possible to achieve this through proper test association and updating the related fields.


I updated those 3 other fields and it still didn’t flip. Can you give me an example of what I might want to set those 3 fields to if my “@angular/core/testing” unit test named “Hello World” tests the “GreetingComponent” class defined in “src/app/greetingComponent.ts” file, and then Karma runs it and reports it out in NUnit format, and then my PublishTestResults Azure Pipelines task publishes that NUnit-formatted file?

To ensure that the Microsoft.VSTS.TCM.AutomationStatus flips to “Automated,” the values for the fields Microsoft.VSTS.TCM.AutomatedTestId, Microsoft.VSTS.TCM.AutomatedTestName, and Microsoft.VSTS.TCM.AutomatedTestStorage need to be set correctly. Based on your scenario, where you’re using an Angular unit test framework (@angular/core/testing) with Karma running tests and publishing results in NUnit format, here’s how you might set these fields:

Example Field Values

  1. Microsoft.VSTS.TCM.AutomatedTestId: This is typically a unique identifier for the test. Since NUnit doesn’t natively generate unique IDs for tests, you can use a combination of the namespace, class name, and method name as a pseudo-ID. For your test:
src/app/greetingComponent.HelloWorld
  1. Microsoft.VSTS.TCM.AutomatedTestName: This should be the name of the test method. In your case:
Hello World
  1. Microsoft.VSTS.TCM.AutomatedTestStorage: This field specifies the file where the test is defined. It should be the relative path to the file containing the test:
src/app/greetingComponent.ts

Explanation of Field Values

  • AutomatedTestId: Combines the location and test name to uniquely identify this test in Azure DevOps.
  • AutomatedTestName: Matches the exact name of your test method as defined in your code.
  • AutomatedTestStorage: Points to the file where the test is implemented, enabling traceability.

Additional Steps

After setting these fields, ensure that:

  1. The NUnit results file published by your PublishTestResults@2 task includes these mappings.
  2. The PublishTestResults task is correctly configured to process NUnit results files:
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'NUnit'
    testResultsFiles: '**/TEST-*.xml'
    publishRunAttachments: true
  1. The NUnit results file includes sufficient metadata (e.g., fully qualified names) for Azure DevOps to link these fields properly.

Debugging Tips

If these fields are correctly set but the status still doesn’t flip:

  • Verify that your NUnit results file contains valid entries that Azure DevOps can parse.
  • Check if there are any errors or warnings in the pipeline logs related to publishing test results.
  • Ensure that your pipeline agent has access to update work items in Azure DevOps.

If issues persist, it could be related to how Azure DevOps interprets NUnit results or a bug in processing these fields. You may need to contact Microsoft support or explore alternative ways to associate tests programmatically.


Thank you! I just noticed through your elaboration that I had an unnecessary AutomatedTestStorage (whatever that is…?) and actually was missing “AutomatedTestId”.

I’m glad my explanation helped you identify the issue! Your observation is astute and highlights a common misunderstanding in setting up automated test associations in Azure DevOps. Let me clarify these fields for you:

  1. AutomatedTestId: This is indeed crucial. It’s a unique identifier for your test method, typically combining the namespace, class, and method name. It’s essential for Azure DevOps to uniquely identify and track your test.
  2. AutomatedTestStorage: While it might seem unnecessary, this field is actually important. It specifies the file path where the test method is defined, helping with traceability and linking in Azure DevOps.
  3. AutomatedTestName: This is usually the name of your test method.

All three fields work together to provide a complete picture of your automated test within Azure DevOps. By ensuring all these fields are correctly populated, you increase the likelihood of successful test case association and automation status updates.

Remember, for Angular tests published via NUnit format, you might need to adjust how these fields are populated based on how Karma and your NUnit adapter are formatting the test results. If you continue to face issues, you might need to examine the NUnit XML output to ensure it’s formatting these fields in a way Azure DevOps can interpret correctly.


Can you link me to some demo repos that do all of this correctly and are Angular projects?

Here are some demo repositories and resources that can help you set up Azure DevOps pipelines for Angular projects, including automated testing and publishing test results correctly:

  1. LearnSmartCoding Repository This repository demonstrates how to set up a CI/CD pipeline for Angular applications using Azure DevOps. It includes steps for managing source code, automating deployments, and configuring pipelines. Repository: [https://github.com/learnsmartcoding/online-course-ui]10
  2. Dev.to Angular Pipeline Recipe A straightforward guide to creating an Azure DevOps pipeline for Angular 8+ projects, including unit testing and publishing test results. It provides detailed steps for configuring Karma for CI environments and publishing JUnit test results. Article: [A Recipe: Azure DevOps build pipeline for Angular 8+]11
  3. Ciemasen’s Angular Pipeline Guide This article explains how to build and run unit tests with Azure DevOps for Angular applications. It includes YAML pipeline examples for installing dependencies, running tests, publishing test results, and code coverage reports. Article: [How to build Angular in Azure DevOps]12
  4. Microsoft Starter App A starter template repository for deploying an Angular app using Azure Static Web Apps and Azure DevOps pipelines. While focused on deployment, it provides a good foundation for integrating testing workflows. Article: [Deploy an Angular app on Azure Static Web Apps]13
  5. Dev.to Continuous Integration Guide A demo project showcasing how to integrate an Angular CLI application with Azure DevOps pipelines, including building, testing, and deploying the app. Article: [Continuously Integrating Angular with Azure DevOps]14

These resources provide both practical examples and step-by-step guides to help you configure your pipelines correctly for automated testing, publishing results, and associating test cases with work items in Azure DevOps.


I mean with the specific linking thing I’m up to.

I apologize for the misunderstanding. You’re right to ask for more specific examples related to test case linking in Angular projects with Azure DevOps. Unfortunately, there aren’t many public repositories that demonstrate this exact scenario, as it’s a rather specific use case.

However, I can provide you with a conceptual example of how this might be set up:

  1. In your Angular test file (e.g., greeting.component.spec.ts): ```typescript import { ComponentFixture, TestBed } from ‘@angular/core/testing’; import { GreetingComponent } from ‘./greeting.component’;

describe(‘GreetingComponent’, () => { let component: GreetingComponent; let fixture: ComponentFixture;

beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ GreetingComponent ] }) .compileComponents(); });

beforeEach(() => { fixture = TestBed.createComponent(GreetingComponent); component = fixture.componentInstance; fixture.detectChanges(); });

it(‘should create’, () => { expect(component).toBeTruthy(); });

// This test would be linked to a specific test case in Azure DevOps it(‘should display greeting message’, () => { component.name = ‘John’; fixture.detectChanges(); const compiled = fixture.nativeElement; expect(compiled.querySelector(‘h1’).textContent).toContain(‘Hello, John!’); }); });


2. In your Azure Pipeline YAML file:
```yaml
trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '14.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
  displayName: 'npm install and test'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/TESTS-*.xml'
  condition: succeededOrFailed()

- task: TestCaseAssociation@1
  inputs:
    testCaseFilters: |
      GreetingComponent.should display greeting message
    testCaseIds: '123'  # Replace with your actual test case ID
  1. Then, you would use the Azure DevOps REST API to update the test case fields: ```python import requests

url = “https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0”

payload = [ { “op”: “add”, “path”: “/fields/Microsoft.VSTS.TCM.AutomatedTestName”, “value”: “should display greeting message” }, { “op”: “add”, “path”: “/fields/Microsoft.VSTS.TCM.AutomatedTestId”, “value”: “GreetingComponent.should display greeting message” }, { “op”: “add”, “path”: “/fields/Microsoft.VSTS.TCM.AutomatedTestStorage”, “value”: “src/app/greeting/greeting.component.spec.ts” } ]

headers = { ‘Content-Type’: ‘application/json-patch+json’, ‘Authorization’: ‘Basic ' }

response = requests.request(“PATCH”, url, headers=headers, json=payload)

print(response.text) ```

This is a conceptual example and would need to be adapted to your specific project structure and needs. Unfortunately, I couldn’t find a public repository that demonstrates this exact workflow for Angular projects.

  1. https://stackoverflow.com/questions/45370303/associate-to-test-case-is-not-enabled-in-visual-studio  2

  2. https://stackoverflow.com/questions/69488417/how-to-link-azure-pipeline-test-results-to-test-cases  2 3

  3. https://learn.microsoft.com/en-us/azure/devops/test/associate-automated-test-with-test-case?view=azure-devops  2 3

  4. https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-test-results-v2?view=azure-pipelines 

  5. https://learn.microsoft.com/en-us/azure/devops/test/associate-automated-test-with-test-case?view=azure-devops  2

  6. https://marketplace.visualstudio.com/items?itemName=GoatWranglers.build-release-task  2 3 4

  7. https://learn.microsoft.com/vi-vn/azure/devops/test/associate-automated-test-with-test-case?view=azure-devops-2020 

  8. https://stackoverflow.com/questions/61393409/azure-devops-api-update-testcase-automation-status  2 3 4 5

  9. https://stackoverflow.com/questions/70832644/what-is-the-significance-of-api-versions-in-azure-devops 

  10. https://www.youtube.com/watch?v=OlJD-XNUNXc 

  11. https://dev.to/ib1/a-recipe-azure-devops-build-pipeline-for-angular-8-gm4 

  12. https://ciemasen.com/articles/how-to-build-angular-in-azure-devops 

  13. https://learn.microsoft.com/en-us/azure/static-web-apps/deploy-angular 

  14. https://dev.to/thisdotmedia/continuously-integrating-angular-with-azure-devops-2k9l