Skip to content

Commit

Permalink
Report test categories
Browse files Browse the repository at this point in the history
Fix #12
NUnitAdapter doesn't provide info about test description
  • Loading branch information
nvborisenko committed Sep 6, 2019
1 parent 0c88f6d commit 83cbb0f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.5.0">
<PrivateAssets>all;</PrivateAssets>
</PackageReference>
<PackageReference Include="ReportPortal.Shared" Version="2.3.1">
<PackageReference Include="ReportPortal.Shared" Version="2.3.2">
<PrivateAssets>contentfiles;analyzers;</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
40 changes: 34 additions & 6 deletions src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void Events_TestRunStart(object sender, TestRunStartEventArgs e)
requestNewLaunch.Tags = _config.GetValues(ConfigurationPath.LaunchTags, new List<string>()).ToList();

// see wether we need use external launch
var launchId = _config.GetValue<string>("Launch:Id", "");
var launchId = _config.GetValue("Launch:Id", "");

if (string.IsNullOrEmpty(launchId))
{
Expand Down Expand Up @@ -140,12 +140,10 @@ private void Events_TestResult(object sender, TestResultEventArgs e)
}
else
{

testName = e.Result.TestCase.DisplayName ?? fullName.Split('.').Last();

fullPath = fullName.Substring(0, fullName.Length - testName.Length - 1);
}


var rootNamespaces = _config.GetValues<string>("rootNamespaces", null);
if (rootNamespaces != null)
Expand All @@ -159,13 +157,43 @@ private void Events_TestResult(object sender, TestResultEventArgs e)

var suiteReporter = GetOrStartSuiteNode(fullPath, e);

// find description
var testDescription = e.Result.TestCase.Traits.FirstOrDefault(x => x.Name == "Description")?.Value;

if (e.Result.TestCase.ExecutorUri.ToString().ToLower().Contains("mstestadapter"))
{
var testProperty = e.Result.TestCase.Properties.FirstOrDefault(p => p.Id == "Description");
if (testProperty != null)
{
testDescription = e.Result.TestCase.GetPropertyValue(testProperty).ToString();
}
}

// find categories
var testCategories = e.Result.TestCase.Traits.Where(t => t.Name.ToLower() == "Category".ToLower()).Select(x => x.Value).ToList();

if (e.Result.TestCase.ExecutorUri.ToString().ToLower().Contains("mstestadapter"))
{
var testProperty = e.Result.TestCase.Properties.FirstOrDefault(p => p.Id == "MSTestDiscoverer.TestCategory");
if (testProperty != null)
{
testCategories.AddRange((string[])e.Result.TestCase.GetPropertyValue(testProperty));
}
} else if (e.Result.TestCase.ExecutorUri.ToString().ToLower().Contains("nunit"))
{
var testProperty = e.Result.TestCase.Properties.FirstOrDefault(p => p.Id == "NUnit.TestCategory");
if (testProperty != null)
{
testCategories.AddRange((string[])e.Result.TestCase.GetPropertyValue(testProperty));
}
}

// start test node
var description = e.Result.TestCase.Traits.FirstOrDefault(x => x.Name == "Description");
var startTestRequest = new StartTestItemRequest
{
Name = testName,
Description = description?.Value,
Tags = e.Result.TestCase.Traits.Where(t => t.Name.ToLower() == "Category".ToLower()).Select(x => x.Value).ToList(),
Description = testDescription,
Tags = testCategories,
StartTime = e.Result.StartTime.UtcDateTime,
Type = TestItemType.Step
};
Expand Down

0 comments on commit 83cbb0f

Please sign in to comment.