Skip to content

Commit

Permalink
Add some simple integration tests
Browse files Browse the repository at this point in the history
Add some tests to simplify testing changes to MEWT and SEWT. They must be run one at a time, but it's better than the manual I was doing before.
  • Loading branch information
Gwindalmir committed Oct 2, 2019
1 parent bcfa519 commit fe4973f
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MEWorkshopTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Phoenix.MEWorkshopTool
{
class Program
public class Program
{
public static int Main(string[] args)
{
Expand Down
2 changes: 1 addition & 1 deletion SEWorkshopTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Phoenix.SEWorkshopTool
{
class Program
public class Program
{
public static int Main(string[] args)
{
Expand Down
104 changes: 104 additions & 0 deletions Tests/IntegrationBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Phoenix.WorkshopTool.Tests
{
[TestFixture]
[RequiresThread]
[NonParallelizable]
public abstract class IntegrationBase
{
#region Base Setup
protected readonly string _parameterPrefix = "SE";
protected string[] _extraArguments = new string[0];

public IntegrationBase()
{
if (this.GetType().Namespace.EndsWith("ME"))
_parameterPrefix = "ME";
}

protected int LaunchMain(string[] args)
{
if (_parameterPrefix == "SE")
{
return SEWorkshopTool.Program.Main(args);
}
else
{
// ME calls GetEntryAssembly, which is null when called from NUnit
SetEntryAssembly(typeof(MEWorkshopTool.Program).Assembly);
return MEWorkshopTool.Program.Main(args);
}
}

/// <summary>
/// Allows setting the Entry Assembly when needed.
/// Use AssemblyUtilities.SetEntryAssembly() as first line in XNA ad hoc tests
/// </summary>
/// <param name="assembly">Assembly to set as entry assembly</param>
public static void SetEntryAssembly(Assembly assembly)
{
AppDomainManager manager = new AppDomainManager();
FieldInfo entryAssemblyfield = manager.GetType().GetField("m_entryAssembly", BindingFlags.Instance | BindingFlags.NonPublic);
entryAssemblyfield.SetValue(manager, assembly);

AppDomain domain = AppDomain.CurrentDomain;
FieldInfo domainManagerField = domain.GetType().GetField("_domainManager", BindingFlags.Instance | BindingFlags.NonPublic);
domainManagerField.SetValue(domain, manager);
}

[OneTimeSetUp]
public virtual void OneTimeSetup()
{
Environment.CurrentDirectory = TestContext.Parameters[$"{_parameterPrefix}.Install"];

if (TestContext.Parameters.Exists($"{_parameterPrefix}.AppData"))
{
_extraArguments = new[] { "--appdata", TestContext.Parameters[$"{_parameterPrefix}.AppData"] };
}

}
#endregion Base Setup

#region Common Tests
[Test]
[Explicit]
public void DownloadMod()
{
var args = new List<string>(new[] { "--download", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModIDToDownload"], "--extract" });
args.AddRange(_extraArguments);

var exitCode = LaunchMain(args.ToArray());
Assert.That(exitCode, Is.EqualTo(0));
}

[Test]
[Explicit]
public void UploadMod()
{
var args = new List<string>(new[] { "--upload", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModNameToUpload"], "--tags", "Mod" });
args.AddRange(_extraArguments);

var exitCode = LaunchMain(args.ToArray());
Assert.That(exitCode, Is.EqualTo(0));
}

[Test]
[Explicit]
public void UpdateTags()
{
var args = new List<string>(new[] { "--update-only", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModNameToUpload"], "--tags", "Mod,Other" });
args.AddRange(_extraArguments);

var exitCode = LaunchMain(args.ToArray());
Assert.That(exitCode, Is.EqualTo(0));
}
#endregion Common Tests
}
}
10 changes: 10 additions & 0 deletions Tests/ME/IntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using NUnit.Framework;
using System.Collections.Generic;

namespace Phoenix.WorkshopTool.Tests.ME
{
// Medieval Engineers MEWT Integration tests
public class Integration : IntegrationBase
{
}
}
10 changes: 10 additions & 0 deletions Tests/SE/IntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using NUnit.Framework;
using System.Collections.Generic;

namespace Phoenix.WorkshopTool.Tests.SE
{
// Space Engineers SEWT Integration tests
public class Integration : IntegrationBase
{
}
}
28 changes: 28 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>

<IsPackable>false</IsPackable>

<AssemblyName>Phoenix.WorkshopTool.Tests</AssemblyName>

<RootNamespace>Phoenix.WorkshopTool.Tests</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MEWorkshopTool\MEWorkshopTool.csproj" />
<ProjectReference Include="..\SEWorkshopTool\SEWorkshopTool.csproj" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions Tests/tests.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<!-- Path relative to solution directory -->
<ResultsDirectory>.\TestResults</ResultsDirectory>
<TargetPlatform>x64</TargetPlatform>
<TargetFrameworkVersion>Framework45</TargetFrameworkVersion>
</RunConfiguration>

<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name="SE.Install" value="D:\Program Files\Steam\SteamApps\common\SpaceEngineers" />
<Parameter name="SE.ModIDToDownload" value="637504549" />
<Parameter name="SE.ModNameToUpload" value="test-dev" />
<!-- <Parameter name="SE.AppData" value="" /> -->

<Parameter name="ME.Install" value="D:\Program Files\Steam\SteamApps\common\MedievalEngineers" />
<Parameter name="ME.ModIDToDownload" value="1342545091" />
<Parameter name="ME.ModNameToUpload" value="PickaxeMod_mewt" />
<!-- <Parameter name="ME.AppData" value="" /> -->
</TestRunParameters>

<!-- Adapter Specific sections -->
</RunSettings>
13 changes: 11 additions & 2 deletions WorkshopTool.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.28307.489
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SEWorkshopTool", "SEWorkshopTool\SEWorkshopTool.csproj", "{B45A96AB-94B8-46C2-813A-32FD0E1D8390}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "WorkshopToolCommon", "WorkshopToolCommon\WorkshopToolCommon.shproj", "{F854B41F-D141-467D-A009-74BB31E7A873}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEWorkshopTool", "MEWorkshopTool\MEWorkshopTool.csproj", "{951AC7F6-8487-428E-8BFF-B26D689FD259}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{C8E85CFE-78CA-4450-A23D-55FAC0D16BD9}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
WorkshopToolCommon\WorkshopToolCommon.projitems*{951ac7f6-8487-428e-8bff-b26d689fd259}*SharedItemsImports = 4
Expand All @@ -28,8 +30,15 @@ Global
{951AC7F6-8487-428E-8BFF-B26D689FD259}.Debug|Any CPU.Build.0 = Debug|Any CPU
{951AC7F6-8487-428E-8BFF-B26D689FD259}.Release|Any CPU.ActiveCfg = Release|Any CPU
{951AC7F6-8487-428E-8BFF-B26D689FD259}.Release|Any CPU.Build.0 = Release|Any CPU
{C8E85CFE-78CA-4450-A23D-55FAC0D16BD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8E85CFE-78CA-4450-A23D-55FAC0D16BD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8E85CFE-78CA-4450-A23D-55FAC0D16BD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8E85CFE-78CA-4450-A23D-55FAC0D16BD9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E9E16C0-916C-4768-8FE1-A39AB0A67AE5}
EndGlobalSection
EndGlobal

0 comments on commit fe4973f

Please sign in to comment.