我正在尝试从 C# 执行自动化的 Azure DevOps TestPlan,但我没有找到执行此操作的所有文档。
这是我的代码示例:
string organizationName = "...";
string projectName = "...";
int planId = ...;
string definitionName = "...";
int definitionId = ...;
string releaseName = "...";
Uri organizationUrl = await VssConnectionHelper.GetOrganizationUrlAsync(organizationName);
VssConnection connection = new VssConnection(organizationUrl, new VssClientCredentials());
BuildHttpClient buildClnt = connection.GetClient<BuildHttpClient>();
Build build = await buildClnt.GetLatestBuildAsync(projectName, definitionName);
Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference testPlanRef = new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference(planId.ToString());
int[] pointIds = new int[] { 1 };
ReleaseHttpClient releaseClnt = connection.GetClient<ReleaseHttpClient>();
ReleaseStartMetadata releaseStartMetadata = new ReleaseStartMetadata()
{
DefinitionId = definitionId
};
Release release = await releaseClnt.CreateReleaseAsync(releaseStartMetadata, projectName);
RunCreateModel testRunModel = new RunCreateModel(
name : releaseName,
pointIds : pointIds,
plan : testPlanRef,
buildId : build.Id,
isAutomated : true,
releaseUri : release.Url
);
TestManagementHttpClient testMngmnt = connection.GetClient<TestManagementHttpClient>();
TestRun testRun = await testMngmnt.CreateTestRunAsync(testRunModel, projectName);
当我执行此操作时,我收到一条异常,并显示消息“必须指定发布 ID 和发布环境 ID”。 我在互联网上搜索了如何创建发布环境并将其传递给函数,但没有任何运气。
有谁可以帮我解决这个问题吗?
我通过以下步骤解决了以编程方式启动自动化测试的问题:
我不知道这是否是正确的方法,但它对我有用。