Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Nov 8, 2024
1 parent ed04d97 commit bea5be1
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Tests/Reqnroll.SystemTests/Generation/GenerationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public void GeneratorAllIn_sample_can_be_handled()
ExecuteTests();

ShouldAllScenariosPass();

ShouldFinishWithoutTestExecutionWarnings();
}

[TestMethod]
Expand Down
14 changes: 14 additions & 0 deletions Tests/Reqnroll.SystemTests/Generation/NUnitGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ protected override void TestInitialize()
_testRunConfiguration.UnitTestProvider = UnitTestProvider.NUnit3;
}

[TestMethod]
public void GeneratorAllIn_sample_can_be_handled_by_NUnit4()
{
_testRunConfiguration.UnitTestProvider = UnitTestProvider.NUnit4;

PrepareGeneratorAllInSamples();

ExecuteTests();

ShouldAllScenariosPass();

ShouldFinishWithoutTestExecutionWarnings();
}

protected override void AssertIgnoredScenarioOutlineExampleHandled()
{
_vsTestExecutionDriver.LastTestExecutionResult.LeafTestResults
Expand Down
5 changes: 5 additions & 0 deletions Tests/Reqnroll.SystemTests/SystemTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ protected void ShouldAllScenariosPass(int? expectedNrOfTestsSpec = null)
_vsTestExecutionDriver.LastTestExecutionResult.Succeeded.Should().Be(expectedNrOfTests, "all tests should pass");
}

protected void ShouldFinishWithoutTestExecutionWarnings()
{
_vsTestExecutionDriver.LastTestExecutionResult.Warnings.Should().BeEmpty();
}

protected int ConfirmAllTestsRan(int? expectedNrOfTestsSpec)
{
if (expectedNrOfTestsSpec == null && _preparedTests == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static string ToName(this UnitTestProvider unitTestProvider)
{
case UnitTestProvider.MSTest: return "MSTest";
case UnitTestProvider.NUnit2: return "NUnit2";
case UnitTestProvider.NUnit3: return "NUnit";
case UnitTestProvider.NUnit3:
case UnitTestProvider.NUnit4:
return "NUnit";
case UnitTestProvider.xUnit: return "XUnit";
default: throw new ArgumentOutOfRangeException(nameof(unitTestProvider), unitTestProvider, "value is not known");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class ProjectBuilder
public const string NUnit3PackageVersion = "3.13.1";
public const string NUnit3TestAdapterPackageName = "NUnit3TestAdapter";
public const string NUnit3TestAdapterPackageVersion = "3.17.0";
public const string NUnit4PackageName = "NUnit";
public const string NUnit4PackageVersion = "4.2.2";
public const string NUnit4TestAdapterPackageName = "NUnit3TestAdapter";
public const string NUnit4TestAdapterPackageVersion = "4.6.0";
private const string XUnitPackageVersion = "2.4.2";
private const string MSTestPackageVersion = "2.2.8";
private const string InternalJsonPackageName = "SpecFlow.Internal.Json";
Expand Down Expand Up @@ -253,7 +257,10 @@ private void EnsureProjectExists()
ConfigureXUnit();
break;
case UnitTestProvider.NUnit3:
ConfigureNUnit();
ConfigureNUnit3();
break;
case UnitTestProvider.NUnit4:
ConfigureNUnit4();
break;
default:
throw new InvalidOperationException(@"Invalid unit test provider.");
Expand All @@ -263,7 +270,7 @@ private void EnsureProjectExists()
AddAdditionalStuff();
}

private void ConfigureNUnit()
private void ConfigureNUnit3()
{
_project.AddNuGetPackage(NUnit3PackageName, NUnit3PackageVersion);
_project.AddNuGetPackage(NUnit3TestAdapterPackageName, NUnit3TestAdapterPackageVersion);
Expand All @@ -277,6 +284,20 @@ private void ConfigureNUnit()
}
}

private void ConfigureNUnit4()
{
_project.AddNuGetPackage(NUnit4PackageName, NUnit4PackageVersion);
_project.AddNuGetPackage(NUnit4TestAdapterPackageName, NUnit4TestAdapterPackageVersion);


if (IsReqnrollFeatureProject)
{
_project.AddNuGetPackage("Reqnroll.NUnit", _currentVersionDriver.ReqnrollNuGetVersion,
new NuGetPackageAssembly(GetReqnrollPublicAssemblyName("Reqnroll.NUnit.ReqnrollPlugin.dll"), "net462\\Reqnroll.NUnit.ReqnrollPlugin.dll"));
Configuration.Plugins.Add(new ReqnrollPlugin("Reqnroll.NUnit", ReqnrollPluginType.Runtime));
}
}

private void ConfigureXUnit()
{
if (_project.ProjectFormat == ProjectFormat.New)
Expand Down Expand Up @@ -348,6 +369,7 @@ private void AddUnitTestProviderSpecificConfig()
_project.AddFile(new ProjectFile("XUnitConfiguration.cs", "Compile", "using Xunit; [assembly: CollectionBehavior(CollectionBehavior.CollectionPerClass, MaxParallelThreads = 4)]"));
break;
case UnitTestProvider.NUnit3 when _parallelTestExecution:
case UnitTestProvider.NUnit4 when _parallelTestExecution:
_project.AddFile(new ProjectFile("NUnitConfiguration.cs", "Compile", "[assembly: NUnit.Framework.Parallelizable(NUnit.Framework.ParallelScope.All)]"));
break;
case UnitTestProvider.MSTest when _parallelTestExecution:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,29 @@ private TestExecutionResult CalculateTestExecutionResultFromTrx(XDocument trx, T
private TestExecutionResult GetCommonTestExecutionResult(XDocument trx, string output, IEnumerable<string> reportFiles, string logFileContent)
{
var testRunElement = trx.Descendants(_testRunElementName).Single();
var summaryElement = testRunElement.Element(_xmlns + "ResultSummary")?.Element(_xmlns + "Counters")
?? throw new InvalidOperationException("Invalid document; result summary counters element not found.");
var summaryElement = testRunElement.Element(_xmlns + "ResultSummary")
?? throw new InvalidOperationException("Invalid document; result summary element not found."); ;
var summaryCountersElement = summaryElement?.Element(_xmlns + "Counters")
?? throw new InvalidOperationException("Invalid document; result summary counters element not found.");

var totalAttribute = summaryElement.Attribute("total");
var executedAttribute = summaryElement.Attribute("executed");
var passedAttribute = summaryElement.Attribute("passed");
var failedAttribute = summaryElement.Attribute("failed");
var inconclusiveAttribute = summaryElement.Attribute("inconclusive");
var totalAttribute = summaryCountersElement.Attribute("total");
var executedAttribute = summaryCountersElement.Attribute("executed");
var passedAttribute = summaryCountersElement.Attribute("passed");
var failedAttribute = summaryCountersElement.Attribute("failed");
var inconclusiveAttribute = summaryCountersElement.Attribute("inconclusive");

int.TryParse(totalAttribute?.Value, out int total);
int.TryParse(executedAttribute?.Value, out int executed);
int.TryParse(passedAttribute?.Value, out int passed);
int.TryParse(failedAttribute?.Value, out int failed);
int.TryParse(inconclusiveAttribute?.Value, out int inconclusive);

var runInfos = summaryElement.Element(_xmlns + "RunInfos")?.Elements(_xmlns + "RunInfo") ?? Enumerable.Empty<XElement>();
var warnings = runInfos
.Where(ri => "Warning".Equals(ri.Attribute("outcome")?.Value, StringComparison.InvariantCultureIgnoreCase))
.Select(ri => ri.Element(_xmlns + "Text")?.Value ?? "[no warning text]")
.ToArray();

var testResults = GetTestResults(testRunElement, _xmlns);
var leafTestResults =
testResults.Where(tr => tr.InnerResults.Count == 0)
Expand All @@ -84,6 +92,7 @@ private TestExecutionResult GetCommonTestExecutionResult(XDocument trx, string o
Succeeded = passed,
Failed = failed,
Pending = inconclusive,
Warnings = warnings
};
}

Expand All @@ -93,7 +102,9 @@ private TestExecutionResult CalculateUnitTestProviderSpecificTestExecutionResult
{
case UnitTestProvider.xUnit: return CalculateXUnitTestExecutionResult(testExecutionResult, trx);
case UnitTestProvider.MSTest: return CalculateMsTestTestExecutionResult(testExecutionResult);
case UnitTestProvider.NUnit3: return CalculateNUnitTestExecutionResult(testExecutionResult);
case UnitTestProvider.NUnit3:
case UnitTestProvider.NUnit4:
return CalculateNUnitTestExecutionResult(testExecutionResult);
default: throw new NotSupportedException($"The specified unit test provider is not supported: {testRunConfiguration.UnitTestProvider}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class TestExecutionResult

public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }

public string[] Warnings { get; set; }
}

public class TestResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum UnitTestProvider
{
MSTest,
xUnit,
NUnit4,
NUnit3,
NUnit2
}

0 comments on commit bea5be1

Please sign in to comment.