Skip to content

Commit

Permalink
junit int staeted
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-khatko committed Feb 9, 2014
1 parent 5850f66 commit 36e837f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
20 changes: 14 additions & 6 deletions CLAPOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public string ProvidedVerb()
static void NoInput()
{
Console.WriteLine(
@"This is command line utility to get tests from TFS or to update results of tests inside TFS.
Try -h option for more."
@"This is command line utility to get tests from TFS or to update results of tests inside TFS.
Try -h option for more."
);
}

Expand All @@ -77,13 +77,17 @@ static void help()
[Verb(Aliases = "get",
Description = "Exports TFS tests from provided project and testplan. Please fill config file beforehand\nExample usage: tfs_cli get"
)]
static void get_tests(
static void get_tests(
[DefaultValue("tests.xml"), DescriptionAttribute("Filename for tests export")]
string output
string output,
[AliasesAttribute("tp"), DefaultValue(""), DescriptionAttribute("Testplan to get tests from (overrides .config option)")]
string testplan
)
{
_verb = "get_tests";
_opts["output"] = output;
if (testplan != "")
_opts["testplan"] = testplan;
}

[Verb(Aliases = "upd", Description = "Updates TFS test with provided attributes. Please fill config file beforehand\nExample usage: tfs_cli.exe u /rt=\"my test run\" /ts=\"testsuite\" /tn=\"test name\" /to=Passed /duration=1")]
Expand All @@ -101,7 +105,7 @@ static void update_test(
[AliasesAttribute("ra"), DescriptionAttribute("Run attachment. E.g. overall run report")]
[FileExists]
string run_attachment,
[RequiredAttribute, AliasesAttribute("ts"), DescriptionAttribute("Test suite name")]
[AliasesAttribute("ts"), DescriptionAttribute("Test suite name")]
string test_suite_name,
[RequiredAttribute, AliasesAttribute("tn"), DescriptionAttribute("Test name")]
string test_name,
Expand All @@ -115,7 +119,9 @@ static void update_test(
string test_error_message,
[AliasesAttribute("ta"), DescriptionAttribute("Test attachment. E.g. test run report")]
[FileExists]
string test_attachment
string test_attachment,
[AliasesAttribute("tp"), DefaultValue(""), DescriptionAttribute("Testplan to get tests from (overrides .config option)")]
string testplan
)
{
_verb = "update_test";
Expand All @@ -132,6 +138,8 @@ string test_attachment
_opts["test_comment"] = test_comment;
_opts["test_error_message"] = test_error_message;
_opts["test_attachment"] = test_attachment;
if (testplan != "")
_opts["testplan"] = testplan;
}

[Verb(Aliases = "enc", Description = "Encrypts provided string to be used in App.config\nUsage: tfs_cli enc <password>")]
Expand Down
1 change: 1 addition & 0 deletions ITfsCliUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ namespace tfs_cli
interface ITfsCliUpdater
{
string UpdateTest(TfsTeamProjectCollection tfs, ITfsCliOptions opts);
string UpdateFromJunit(TfsTeamProjectCollection tfs, ITfsCliOptions opts);
}
}
6 changes: 5 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main(string[] args)
// Init provided options
Parser.RunConsole<CLAPOptions>(args);
var options = CLAPOptions.getOptions();
if (options.GetAll().Count == 0) { Environment.Exit(1); }
if (options.GetAll().Count == 0) { Environment.Exit(1); } // need tests here

// Try to connect first
var cred = (options.Get("login") != null && options.Get("password") != null) ?
Expand All @@ -38,6 +38,10 @@ static void Main(string[] args)
{
updater.UpdateTest(connector.GetTfs(), options);
}
else if (options.ProvidedVerb() == "update_from_junit")
{
updater.UpdateFromJunit(connector.GetTfs(), options);
}
}
catch (Exception e)
{
Expand Down
11 changes: 8 additions & 3 deletions SimpleTfsUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SimpleTfsUpdater : ITfsCliUpdater
{
public string UpdateTest(TfsTeamProjectCollection tfs, ITfsCliOptions opts)
{
// get tfs helper
// get tfs api helper
ITfsApi tfsapi = new FirstTfsApi(tfs);
// get testplan
ITestManagementTeamProject project = tfsapi.GetProject(opts.Get("project"));
Expand Down Expand Up @@ -48,7 +48,7 @@ public string UpdateTest(TfsTeamProjectCollection tfs, ITfsCliOptions opts)
result = run.QueryResults()[i];
}
if (result == null)
TfsCliHelper.ExitWithError(string.Format("Could not find testcase {0} inside testplan {1}", opts.Get("test_name"), testplan.Name));
TfsCliHelper.ExitWithError(string.Format("Could not find testcase {0} inside testsuite {1}", opts.Get("test_name"), testsuite.Title));
// update test reults
// create and populate test iteration
// save test results
Expand All @@ -61,6 +61,11 @@ public string UpdateTest(TfsTeamProjectCollection tfs, ITfsCliOptions opts)
opts.Get("test_error_message"),
opts.Get("test_attachment")
);
}
}

public string UpdateFromJunit(TfsTeamProjectCollection tfs, ITfsCliOptions opts)
{
return "TODO";
}
}
}
13 changes: 10 additions & 3 deletions XmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;

Expand Down Expand Up @@ -56,7 +57,7 @@ private void Append(ITestCase test, XElement root)
xmltest.Add(
new XAttribute("id", test.Id),
new XAttribute("title", test.Title),
new XAttribute("description", test.Description ?? ""),
new XAttribute("description", fromHtml(test.Description) ?? ""),
new XAttribute("state", test.State),
new XAttribute("priority", test.Priority),
new XAttribute("owner", test.OwnerName),
Expand All @@ -71,8 +72,8 @@ private void Append(ITestCase test, XElement root)

a.Add(
new XAttribute("id", action.Id),
new XAttribute("action", step.Title),
new XAttribute("expected_result", step.ExpectedResult)
new XAttribute("action", fromHtml(step.Title)),
new XAttribute("expected_result", fromHtml(step.ExpectedResult))
);
xmltest.Add(a);
}
Expand All @@ -86,5 +87,11 @@ private void Append(ITestCase test, XElement root)
// add this staff to root
root.Add(xmltest);
}

private string fromHtml(string htmlText){
htmlText = htmlText.Replace("</P><P>", Environment.NewLine);
htmlText = System.Text.RegularExpressions.Regex.Replace(htmlText, @"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", String.Empty);
return htmlText;
}
}
}

0 comments on commit 36e837f

Please sign in to comment.