Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scenario tests to be completely metadata driven. #22

Open
MichaelSimons opened this issue Aug 22, 2023 · 2 comments
Open

Refactor scenario tests to be completely metadata driven. #22

MichaelSimons opened this issue Aug 22, 2023 · 2 comments

Comments

@MichaelSimons
Copy link
Member

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)
        }
    }
@MichaelSimons
Copy link
Member Author

cc @mattscheffer

@MichaelSimons
Copy link
Member Author

Source-build utilizes this pattern in it's scenario tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant