Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling vsts properties flow to test context #472

Merged
merged 2 commits into from
Aug 8, 2018

Conversation

abhishkk
Copy link
Contributor

@abhishkk abhishkk commented Aug 6, 2018

Description:
VS IDE has support of association in test explorer. Currently this support is disabled for mstest v2.
Support for mstest v2 will be enabled with this PR: https://devdiv.visualstudio.com/DevDiv/Automated%20Testing/_git/VS/pullrequest/135489?_a=overview

When association is enabled for mstest v2 tests, user can associate mstest v2 tests with a test case and then run it via test plan flow.

In test plan flow, user might need to use tcm properties (like test case id, test run id, test plan id etc) in test method code. This PR contains changes to allow tcm properties to flow to test context.

Validation Scenarios:
Validated that for full framework and net core, tcm properties are properly passed to test context.

Note: In talk with @PBoraMSFT if RFC is required in mstest v2 or not as the flow is controled from IDE. There is a plan to add the documentation on association window in test explorer.

{
var tcmProperties = new Dictionary<TestPlatformObjectModel.TestProperty, object>();

// Return empty proeprties when testCase is null or when test case id is zero.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (testCase == null ||
testCase.GetPropertyValue<int>(Constants.TestCaseIdProperty, default(int)) == 0)
{
return tcmProperties;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prefer returning null here and declare tcmProperties variable after this check has passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done so as to not having null check outside this method context. In case we return null, we can't iterate over it via foreach loop untill there is a null check.

[TestClass]
public class TcmTestPropertiesProviderTests
{
private const string PropertiesJsonWithDuplicateNamedTestCases = "{ \"TestPlanId\":1, \"TestRunId\":4, \"BuildConfigurationId\":0, \"BuildDirectory\":\"C:\\\\deployment\", \"BuildFlavor\":null, \"BuildNumber\":\"4\", \"BuildPlatform\":null, \"BuildUri\":\"vstfs:///Build/Build/4\", \"TfsServerCollectionUrl\":\"http://server/tfs/DefaultCollection/\", \"TeamProject\":\"teamproject\", \"IsInLabEnvironment\":false, \"LabEnvironment\":null, \"TestCases\":[{\"FullyQualifiedName\":\"PassingTest\",\"Source\":\"unittestproject1.dll\",\"TestCaseId\":1311,\"TestPointId\":11,\"TestConfigurationId\":1,\"TestConfigurationName\":\"Windows 10\"},{\"FullyQualifiedName\":\"PassingTest\",\"Source\":\"unittestproject1.dll\",\"TestCaseId\":1312,\"TestPointId\":12,\"TestConfigurationId\":2,\"TestConfigurationName\":\"Windows 8\"},{\"FullyQualifiedName\":\"PassingTest2\",\"Source\":\"unittestproject2.dll\",\"TestCaseId\":1313,\"TestPointId\":13,\"TestConfigurationId\":2,\"TestConfigurationName\":\"Windows 8\"}]}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split this across multiple lines please to increase readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as this was not requried

public void GetTcmPropertiesShouldReturnEmptyDictionaryIfTestCaseIdIsZero()
{
var testCase = new TestCase("PassingTestFomTestCase", new Uri("http://sampleUri/"), "unittestproject1.dll");
var propertiesValue = new object[] { 32, 534, 5, "sample build directory", "sample build flavor", "132456", "sample build platform", "http://sampleBuildUti/", "http://samplecollectionuri/", "sample team project", false, 0, 54, "sample configuration name", 345 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jayaranigarg
Copy link
Member

Should we add some logging to show what values got filled in for properties? It will help in debugging issues.

@abhishkk abhishkk merged commit e50e1f7 into microsoft:master Aug 8, 2018
@abhishkk abhishkk changed the title Enabling tcm properties flow to test context Enabling vsts properties flow to test context Aug 10, 2018
@jayaranigarg
Copy link
Member

microsoft/testfx-docs#36

@anshuls01
Copy link

thanks for resolving the issue. I am still not able to get the vsts Properties in testcontext.
Is there any sample project available?

as per the new changes I tried to access the TCM properties using:
IDictionary<TestPlatformObjectModel.TestProperty, object> tcmProperties = TcmTestPropertiesProvider.GetTcmProperties(null);
certainly compile time error will come, cause TcmTestPropertiesProvider is an internal class.
during Testcase execution, it's important to know the testrun id, Please help.

@jayaranigarg
Copy link
Member

jayaranigarg commented Sep 30, 2019

@anshuls01: Request you to not post queries on closed Pull Requests. Please create separate issue for your queries.

Meanwhile, you can refer to this to see how to access these properties.
Note - TcmTestPropertiesProvider is not supposed to be exposed to the users.

@microsoft microsoft locked as resolved and limited conversation to collaborators Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants