Refactor scenario tests to be completely metadata driven. #22
Open
Description
opened on Aug 22, 2023
Currently the scenarios tests are defined with the following pattern:
[Theory]
[MemberData(nameof(GetLanguages))]
public void VerifyClasslibTemplate(DotNetLanguage language)
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests), language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.ClassLib,
DotNetSdkActions.Build | DotNetSdkActions.Publish);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}
[Theory]
[MemberData(nameof(GetLanguages))]
public void VerifyXUnitTemplate(DotNetLanguage language)
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests), language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.XUnit,
DotNetSdkActions.Test);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}
There is a fair amount of overhead/duplication with this pattern when the SdkTemplateTest constructor call is the differing logic. MemberData could be utilized to define all of this in a more metadata driven approach. Adding a new test case requires defining a single list declaring the test scenario metadata.
[Theory]
[MemberData(nameof(GetScenarios))]
public void VerifyXUnitTemplate(TestScenario testScenario)
{
testScenario.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}
private static IEnumerable<TestScenario> GetScenarios()
{
foreach (DotNetLanguage language in Enum.GetValues<DotNetLanguage>())
{
yield return new(language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.XUnit, DotNetSdkActions.Test),
yield return new(language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.ClassLib, DotNetSdkActions.Build | DotNetSdkActions.Publish)
}
}
Metadata
Assignees
Labels
No labels
Activity