1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Move to using test methods for better separation

This commit is contained in:
smoogipoo 2020-03-02 12:20:25 +09:00
parent 239cfddcbb
commit ce7cbf29ca
4 changed files with 48 additions and 30 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
@ -20,24 +21,26 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
{
}
protected override ModTestCaseData[] CreateTestCases() => new[]
[Test]
public void TestNoAdjustment() => CreateModTest(new ModTestCaseData("no adjustment", new OsuModDifficultyAdjust())
{
new ModTestCaseData("no adjustment", new OsuModDifficultyAdjust())
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
new ModTestCaseData("cs = 10", new OsuModDifficultyAdjust { CircleSize = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
new ModTestCaseData("ar = 10", new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
};
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
});
[Test]
public void TestCircleSize10() => CreateModTest(new ModTestCaseData("cs = 10", new OsuModDifficultyAdjust { CircleSize = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
});
[Test]
public void TestApproachRate10() => CreateModTest(new ModTestCaseData("ar = 10", new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
});
protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score);

View File

@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual
{
public abstract class ModSandboxTestScene : PlayerTestScene
{
protected sealed override bool HasCustomSteps => true;
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(ModSandboxTestScene)
@ -28,14 +30,15 @@ namespace osu.Game.Tests.Visual
private ModTestCaseData currentTest;
public override void SetUpSteps()
protected void CreateModTest(ModTestCaseData testCaseData) => CreateTest(() =>
{
foreach (var testCase in CreateTestCases())
{
AddStep(testCase.Name, () => currentTest = testCase);
base.SetUpSteps();
AddUntilStep("test passed", () => testCase.PassCondition?.Invoke() ?? true);
}
AddStep("set test data", () => currentTest = testCaseData);
});
public override void TearDownSteps()
{
AddUntilStep("test passed", () => currentTest?.PassCondition?.Invoke() ?? true);
base.TearDownSteps();
}
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset);
@ -51,11 +54,6 @@ namespace osu.Game.Tests.Visual
return CreateReplayPlayer(score);
}
/// <summary>
/// Creates the test cases for this test scene.
/// </summary>
protected abstract ModTestCaseData[] CreateTestCases();
/// <summary>
/// Creates the <see cref="TestPlayer"/> for a test case.
/// </summary>

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
@ -14,6 +15,11 @@ namespace osu.Game.Tests.Visual
{
public abstract class PlayerTestScene : RateAdjustedBeatmapTestScene
{
/// <summary>
/// Whether custom test steps are provided. Custom tests should invoke <see cref="CreateTest"/> to create the test steps.
/// </summary>
protected virtual bool HasCustomSteps { get; } = false;
private readonly Ruleset ruleset;
protected Player Player;
@ -37,6 +43,17 @@ namespace osu.Game.Tests.Visual
{
base.SetUpSteps();
if (!HasCustomSteps)
CreateTest(null);
}
protected void CreateTest(Action action)
{
if (action != null && !HasCustomSteps)
throw new InvalidOperationException($"Cannot add custom test steps without {nameof(HasCustomSteps)} being set.");
action?.Invoke();
AddStep(ruleset.RulesetInfo.Name, LoadPlayer);
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
}

View File

@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual
public virtual void SetUpSteps() => addExitAllScreensStep();
[TearDownSteps]
public void TearDownSteps() => addExitAllScreensStep();
public virtual void TearDownSteps() => addExitAllScreensStep();
private void addExitAllScreensStep()
{