gpt4 book ai didi

c# - 使用 TFS api 执行(通过/失败)测试用例?

转载 作者:行者123 更新时间:2023-11-30 13:03:52 24 4
gpt4 key购买 nike

我目前正在开发一个在程序中执行测试用例的程序,我看过How to create a test run and result using the Team Foundation Server API?以及其他各种文章,我仍然遇到很多麻烦。我的目标是找到一个具有特定标题和配置的测试用例,执行它并在失败时添加注释。这只是我一直在搞乱的一些代码

        String server = "http://tfs.net:8080/tfs";
String project = "Project";
// Connect to the TeamFoundationServer.
Console.Write("Connecting to Team Foundation Server {0}...\n", server);

TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(server));
Console.WriteLine("Success!\n");
Console.WriteLine("getting project {0}...\n", project);

ITestManagementTeamProject teamProject = projectCollection.GetService<ITestManagementService>().GetTeamProject(project);

Console.WriteLine("Success!\nGetting test cases...\n\n");
IEnumerable<ITestCase> testCases = teamProject.TestCases.Query("SELECT [Title] FROM WorkItems WHERE State = 'Ready' AND Title CONTAINS 'Phase 1: test case title'");
foreach (ITestCase t in testCases)
Console.WriteLine(t.Title);
ITestSuiteCollection suites = teamProject.TestSuites.Query("SELECT * FROM TestSuite");



ITestConfigurationCollection configs = teamProject.TestConfigurations.Query("Select * FROM TestConfiguration WHERE Name='Mainline Android Phone 2.3'");
ITestConfiguration config = configs[0];

ITestPlan plan = teamProject.TestPlans.Create();
plan.Name = "herpa derp";

ITestSuiteBase suite = teamProject.TestSuites.Find(606);


Console.WriteLine(plan.Name);
Console.WriteLine(suite.Title);
plan.RootSuite.Entries.Add(suite);//Object reference not set to an instance of an object.
plan.Save();

suite.TestCases.AddCases(testCases);
plan.Save();

ITestRun run = plan.CreateTestRun(false);


ITestPointCollection points = plan.QueryTestPoints("SELECT * FROM TestPoint");
foreach (ITestPoint p in points)
{
run.AddTestPoint(p, null);
}
run.Save();
ITestCaseResult result = run.QueryResults()[0];
result.Outcome = TestOutcome.Passed;
result.Save();

//wait dood
Console.Read();

plan.RootSuite.Entries.Add(套件);那是我收到错误“nullreferenceexception was unhandled”的行,它是套件,但对象看起来不错。如果您能提供帮助,请告诉我:)

最佳答案

看起来您可能没有正确访问 teamProject 的权限,无法查看将其传递给计划所需的所有字段。

关于c# - 使用 TFS api 执行(通过/失败)测试用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11320663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com