diff --git a/.travis.yml b/.travis.yml index 078dd3272c..b97d06f49b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ before_install: script: - ./build --configuration=$BUILD_CONFIGURATION - - ./build test+only --configuration=$BUILD_CONFIGURATION --exclude=FlakyNetwork + - ./build test+only --configuration=$BUILD_CONFIGURATION --where="cat != FlakyNetwork" deploy: # Releases (which are tagged) go to github diff --git a/CKAN.sln.DotSettings b/CKAN.sln.DotSettings new file mode 100644 index 0000000000..340b3e4b14 --- /dev/null +++ b/CKAN.sln.DotSettings @@ -0,0 +1,2 @@ + + False \ No newline at end of file diff --git a/Tests/Core/ModuleInstallerDirTest.cs b/Tests/Core/ModuleInstallerDirTest.cs index 8c68516aea..da53492ba4 100644 --- a/Tests/Core/ModuleInstallerDirTest.cs +++ b/Tests/Core/ModuleInstallerDirTest.cs @@ -27,7 +27,7 @@ public class ModuleInstallerDirTest /// Prep environment by setting up a single mod in /// a disposable KSP instance. /// - [TestFixtureSetUp] + [OneTimeSetUp] public void SetUp() { _testModule = TestData.DogeCoinFlag_101_module(); diff --git a/Tests/Core/Relationships/SanityChecker.cs b/Tests/Core/Relationships/SanityChecker.cs index 37fbd983f1..f005096a20 100644 --- a/Tests/Core/Relationships/SanityChecker.cs +++ b/Tests/Core/Relationships/SanityChecker.cs @@ -16,7 +16,7 @@ public class SanityChecker private CKAN.Registry registry; private DisposableKSP ksp; - [TestFixtureSetUp] + [OneTimeSetUp] public void Setup() { ksp = new DisposableKSP(); diff --git a/Tests/Data/TestData.cs b/Tests/Data/TestData.cs index 2d79c6a53f..6b56eab834 100644 --- a/Tests/Data/TestData.cs +++ b/Tests/Data/TestData.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Reflection; using CKAN; using CKAN.Versioning; using Version = CKAN.Version; @@ -12,12 +13,14 @@ static public class TestData { public static string DataDir() { - // TODO: Have this actually walk our directory structure and find - // t/data. This means we can relocate our test executable and - // things will still work. - string current = Directory.GetCurrentDirectory(); - - return Path.Combine(current, "../../../../../Tests/Data"); + // FIXME: Come up with a better solution for test data + // 1. This is fragile with respect to changes in directory structure. + // 2. This forces us to disable ReSharper's test assembly shadow copying + // 3. "Quick" solution is to embed test data as an archive and extract it on demand to a known temporary location. + // But this makes updates hard. + // 4. A better, but much harder solution, is to not require harded files on disk for any of our tests, but that's + // a lot of work. + return Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "../../../../../Tests/Data"); } public static string DataDir(string file) diff --git a/Tests/GUI/Configuration.cs b/Tests/GUI/Configuration.cs index b86b9378f0..ce31423fb6 100644 --- a/Tests/GUI/Configuration.cs +++ b/Tests/GUI/Configuration.cs @@ -10,13 +10,13 @@ public class ConfigurationTests { string tempDir; - [TestFixtureSetUp] + [OneTimeSetUp] public void Setup() { tempDir = TestData.NewTempDir(); } - [TestFixtureTearDown] + [OneTimeTearDown] public void TearDown() { Directory.Delete(tempDir, true); diff --git a/Tests/GUI/GH1866.cs b/Tests/GUI/GH1866.cs index 684dd2a791..26ebd12dd7 100644 --- a/Tests/GUI/GH1866.cs +++ b/Tests/GUI/GH1866.cs @@ -47,7 +47,7 @@ public class GH1866 new NetAsyncModulesDownloader(main.currentUser) );*/ - [TestFixtureSetUp] + [OneTimeSetUp] public void Up() { _instance = new DisposableKSP(); @@ -84,7 +84,7 @@ public void Up() } } - [TestFixtureTearDown] + [OneTimeTearDown] public void Down() { _instance.Dispose(); diff --git a/Tests/GUI/NavigationHistoryTests.cs b/Tests/GUI/NavigationHistoryTests.cs index 3bffc2bd71..0c0355f993 100644 --- a/Tests/GUI/NavigationHistoryTests.cs +++ b/Tests/GUI/NavigationHistoryTests.cs @@ -39,7 +39,7 @@ public void After_SingleHistoryItem_CannotNavigate() Assert.IsFalse(nav.CanNavigateForward); } - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void NavigatingBackward_WhenUnable_ThrowsException() { // arrange @@ -48,14 +48,14 @@ public void NavigatingBackward_WhenUnable_ThrowsException() // act - nav.NavigateBackward(); + TestDelegate act = () => nav.NavigateBackward(); // assert - Assert.Fail(); + Assert.Throws(act); } - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void NavigatingForward_WhenUnable_ThrowsException() { // arrange @@ -64,11 +64,11 @@ public void NavigatingForward_WhenUnable_ThrowsException() // act - nav.NavigateForward(); + TestDelegate act = () => nav.NavigateForward(); // assert - Assert.Fail(); + Assert.Throws(act); } [Test] diff --git a/Tests/NetKAN/SDMod.cs b/Tests/NetKAN/SDMod.cs index 13b337a5a8..103259f1f2 100644 --- a/Tests/NetKAN/SDMod.cs +++ b/Tests/NetKAN/SDMod.cs @@ -26,10 +26,10 @@ public void SD_Version_Select_214() } [Test] - [TestCase("/mod/42/Example/download/1.23", Result="https://spacedock.info/mod/42/Example/download/1.23")] - [TestCase("/mod/42/Example%20With%20Spaces/download/1.23", Result="https://spacedock.info/mod/42/Example%20With%20Spaces/download/1.23")] - [TestCase("/mod/42/Example With Spaces/download/1.23", Result="https://spacedock.info/mod/42/Example%20With%20Spaces/download/1.23")] - [TestCase("/mod/79/Salyut%20Stations%20%26%20Soyuz%20Ferries/download/0.93",Result="https://spacedock.info/mod/79/Salyut%20Stations%20%26%20Soyuz%20Ferries/download/0.93")] + [TestCase("/mod/42/Example/download/1.23", ExpectedResult="https://spacedock.info/mod/42/Example/download/1.23")] + [TestCase("/mod/42/Example%20With%20Spaces/download/1.23", ExpectedResult = "https://spacedock.info/mod/42/Example%20With%20Spaces/download/1.23")] + [TestCase("/mod/42/Example With Spaces/download/1.23", ExpectedResult = "https://spacedock.info/mod/42/Example%20With%20Spaces/download/1.23")] + [TestCase("/mod/79/Salyut%20Stations%20%26%20Soyuz%20Ferries/download/0.93", ExpectedResult = "https://spacedock.info/mod/79/Salyut%20Stations%20%26%20Soyuz%20Ferries/download/0.93")] // GH #816: Ensure URLs with & are encoded correctly. public string SD_URL_encode_816(string path) { diff --git a/Tests/NetKAN/Sources/Curse/CurseApiTests.cs b/Tests/NetKAN/Sources/Curse/CurseApiTests.cs index cdb2c855c5..9d1c417719 100644 --- a/Tests/NetKAN/Sources/Curse/CurseApiTests.cs +++ b/Tests/NetKAN/Sources/Curse/CurseApiTests.cs @@ -14,7 +14,7 @@ public sealed class CurseApiTests { private NetFileCache _cache; - [TestFixtureSetUp] + [OneTimeSetUp] public void TestFixtureSetup() { var tempDirectory = Path.Combine(Path.GetTempPath(), "CKAN", Guid.NewGuid().ToString("N")); @@ -24,7 +24,7 @@ public void TestFixtureSetup() _cache = new NetFileCache(tempDirectory); } - [TestFixtureTearDown] + [OneTimeTearDown] public void TestFixtureTearDown() { Directory.Delete(_cache.GetCachePath(), recursive: true); diff --git a/Tests/NetKAN/Sources/Spacedock/SpacedockApiTests.cs b/Tests/NetKAN/Sources/Spacedock/SpacedockApiTests.cs index 8437539975..814c15db09 100644 --- a/Tests/NetKAN/Sources/Spacedock/SpacedockApiTests.cs +++ b/Tests/NetKAN/Sources/Spacedock/SpacedockApiTests.cs @@ -14,7 +14,7 @@ public sealed class SpacedockApiTests { private NetFileCache _cache; - [TestFixtureSetUp] + [OneTimeSetUp] public void TestFixtureSetup() { var tempDirectory = Path.Combine(Path.GetTempPath(), "CKAN", Guid.NewGuid().ToString("N")); @@ -24,7 +24,7 @@ public void TestFixtureSetup() _cache = new NetFileCache(tempDirectory); } - [TestFixtureTearDown] + [OneTimeTearDown] public void TestFixtureTearDown() { Directory.Delete(_cache.GetCachePath(), recursive: true); diff --git a/Tests/NetKAN/Transformers/GeneratedByTransformerTests.cs b/Tests/NetKAN/Transformers/GeneratedByTransformerTests.cs index 6fb935cd84..770c5a4585 100644 --- a/Tests/NetKAN/Transformers/GeneratedByTransformerTests.cs +++ b/Tests/NetKAN/Transformers/GeneratedByTransformerTests.cs @@ -21,7 +21,7 @@ public void AddsGeneratedByProperty() var transformedJson = result.Json(); // Assert - Assert.That((string)transformedJson["x_generated_by"], Is.StringContaining("netkan"), + Assert.That((string)transformedJson["x_generated_by"], Does.Contain("netkan"), "GeneratedByTransformer should add an x_generated_by property containing the string 'netkan'" ); } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 4f74943931..22be37a586 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -56,9 +56,8 @@ ..\_build\lib\nuget\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\_build\lib\nuget\NUnit.2.6.4\lib\nunit.framework.dll - True + + ..\_build\lib\nuget\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Tests/packages.config b/Tests/packages.config index b0d1f0b38f..1c0eeee824 100644 --- a/Tests/packages.config +++ b/Tests/packages.config @@ -5,5 +5,5 @@ - + \ No newline at end of file diff --git a/build.cake b/build.cake index 21fc378ba1..c235155bb0 100644 --- a/build.cake +++ b/build.cake @@ -1,6 +1,6 @@ #addin "nuget:?package=Cake.SemVer&version=1.0.14" #tool "nuget:?package=ILRepack&version=2.0.12" -#tool "nuget:?package=NUnit.Runners&version=2.6.4" +#tool "nuget:?package=NUnit.ConsoleRunner&version=3.6.1" using System.Text.RegularExpressions; using Semver; @@ -112,7 +112,7 @@ Task("Test+Only") Task("Test-UnitTests+Only") .Does(() => { - var exclude = Argument("exclude", null); + var where = Argument("where", null); var testFile = outDirectory .Combine("CKAN.Tests") @@ -127,9 +127,9 @@ Task("Test-UnitTests+Only") CreateDirectory(nunitOutputDirectory); - NUnit(testFile.FullPath, new NUnitSettings { - Exclude = exclude, - ResultsFile = nunitOutputDirectory.CombineWithFilePath("TestResult.xml") + NUnit3(testFile.FullPath, new NUnit3Settings { + Where = where, + Results = nunitOutputDirectory.CombineWithFilePath("TestResult.xml") }); });