From d0554abd46e6918387605cb2c9cbd82dc6f6f602 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 2 Dec 2022 17:31:24 -0500 Subject: [PATCH] Allow multiple test cases in the TShock test suite Previously, we were initializing TShock before each test. This isn't actually what we want to do, because NUnit will (by default) execute all tests within one instance. Initializing TShock multiple times would cause issues, so let's just do it once at the very beginning, before any tests execute. --- TShockLauncher.Tests/GroupTests.cs | 17 ----------------- TShockLauncher.Tests/TestSetup.cs | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 TShockLauncher.Tests/TestSetup.cs diff --git a/TShockLauncher.Tests/GroupTests.cs b/TShockLauncher.Tests/GroupTests.cs index 61a70b33..5eff651f 100644 --- a/TShockLauncher.Tests/GroupTests.cs +++ b/TShockLauncher.Tests/GroupTests.cs @@ -1,6 +1,4 @@ using NUnit.Framework; -using Terraria; -using Terraria.Localization; using TShockAPI; using TShockAPI.DB; @@ -8,21 +6,6 @@ namespace TShockLauncher.Tests; public class GroupTests { - /// - /// This will be called automatically by nunit before other tests in this class. - /// It serves to initialise the bare minimum variables needed for TShock to be testable without booting up an actual server. - /// - [SetUp] - public static void SetupTShock() - { - Program.SavePath = ""; // 1.4.4.2 staticness introduced this where by default it is null, and any touch to Terraria.Main will use it and cause a crash. - LanguageManager.Instance.SetLanguage(GameCulture.DefaultCulture); // TShockAPI.Localization will fail without ActiveCulture set - Lang.InitializeLegacyLocalization(); // TShockAPI.Localization will fail without preparing NPC names etc - - var ts = new TShock(null); // prepares configs etc - ts.Initialize(); // used to prepare tshocks own static variables, such as the TShock.DB instance - } - /// /// This tests to ensure the group commands work. /// diff --git a/TShockLauncher.Tests/TestSetup.cs b/TShockLauncher.Tests/TestSetup.cs new file mode 100644 index 00000000..0e4abb42 --- /dev/null +++ b/TShockLauncher.Tests/TestSetup.cs @@ -0,0 +1,25 @@ +using NUnit.Framework; +using Terraria; +using Terraria.Localization; +using TShockAPI; + +namespace TShockLauncher.Tests; + +[SetUpFixture] +public class TestSetup +{ + /// + /// This will be called automatically by NUnit before the first test. + /// It serves to initialise the bare minimum variables needed for TShock to be testable without booting up an actual server. + /// + [OneTimeSetUp] + public static void SetupTShock() + { + Program.SavePath = ""; // 1.4.4.2 staticness introduced this where by default it is null, and any touch to Terraria.Main will use it and cause a crash. + LanguageManager.Instance.SetLanguage(GameCulture.DefaultCulture); // TShockAPI.Localization will fail without ActiveCulture set + Lang.InitializeLegacyLocalization(); // TShockAPI.Localization will fail without preparing NPC names etc + + var ts = new TShock(null); // prepares configs etc + ts.Initialize(); // used to prepare tshocks own static variables, such as the TShock.DB instance + } +}