Skip to content

Commit 31a7f11

Browse files
authored
Merge pull request #24 from EmbarkStudios/webbju/function-level-unit-testing
Migrate ServerCodeExciserTest to MSTest.
2 parents 5af7a44 + be8bfc2 commit 31a7f11

File tree

4 files changed

+42
-37
lines changed

4 files changed

+42
-37
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ jobs:
1212
with:
1313
dotnet-version: '6.0.x'
1414
- name: Run tests
15-
run: dotnet run ServerCodeExciserTest.csproj
16-
working-directory: ./ServerCodeExciserTest
15+
run: dotnet test -l "console;verbosity=detailed"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
bin/
88
obj/
99

10+
# MSTest
11+
TestResults/
12+
1013
# Grammar
1114
UnrealAngelscriptParser/Grammar/*
1215
!UnrealAngelscriptParser/Grammar/UnrealAngelscriptLexer.g4
@@ -16,4 +19,4 @@ UnrealAngelscriptParser/Grammar/*
1619
# Input/Output
1720
Input/
1821
Output/
19-
Answers/
22+
Answers/

ServerCodeExciserTest/ExcisionIntegrationTests.cs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
12
using ServerCodeExciser;
23
using ServerCodeExcisionCommon;
3-
using Spectre.Console;
44
using System;
55
using System.IO;
66
using UnrealAngelscriptServerCodeExcision;
77

8-
public class IntegrationTests
8+
[TestClass]
9+
public class ExcisionIntegrationTests
910
{
10-
private static string TestProblemPath = @"Problems";
11-
private static string TestAnswerPath = @"Answers";
11+
private static string DataRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", ".."));
1212

13-
public static int Main(string[] args)
13+
[TestMethod]
14+
public void ExciseAngelscriptCases()
1415
{
1516
int numTestFailures = 0;
1617
int numTestCases = 0;
1718

18-
try
19-
{
20-
// Run for Angelscript
21-
var angelscriptResult = RunExciserIntegrationTests(
22-
".as",
23-
Path.Combine(Environment.CurrentDirectory, TestProblemPath, "Angelscript"),
24-
Path.Combine(Environment.CurrentDirectory, TestAnswerPath, "Angelscript"),
25-
ref numTestFailures,
26-
ref numTestCases);
27-
28-
// Run for "common"
29-
var commonResult = RunExciserIntegrationTests(
30-
".common",
31-
Path.Combine(Environment.CurrentDirectory, TestProblemPath, "Common"),
32-
Path.Combine(Environment.CurrentDirectory, TestAnswerPath, "Common"),
33-
ref numTestFailures,
34-
ref numTestCases);
35-
36-
Console.WriteLine("----------------------------");
37-
Console.WriteLine($"{numTestCases} test(s) executed.");
38-
Console.WriteLine($"{numTestFailures} test(s) failed.");
39-
}
40-
catch (Exception e)
41-
{
42-
AnsiConsole.WriteException(e);
43-
return 1;
44-
}
19+
// Run for Angelscript
20+
var actual = RunExciserIntegrationTests(
21+
".as",
22+
Path.Combine(DataRootDir, "Problems", "Angelscript"),
23+
Path.Combine(DataRootDir, "Answers", "Angelscript"),
24+
ref numTestFailures,
25+
ref numTestCases);
26+
27+
Assert.AreEqual(EExciserReturnValues.Success, actual);
28+
Assert.AreEqual(0, numTestFailures);
29+
}
30+
31+
[TestMethod]
32+
public void ExciseCommonCases()
33+
{
34+
int numTestFailures = 0;
35+
int numTestCases = 0;
36+
37+
// Run for "common"
38+
var actual = RunExciserIntegrationTests(
39+
".common",
40+
Path.Combine(DataRootDir, "Problems", "Common"),
41+
Path.Combine(DataRootDir, "Answers", "Common"),
42+
ref numTestFailures,
43+
ref numTestCases);
4544

46-
return numTestFailures == 0 ? 0 : 1;
45+
Assert.AreEqual(EExciserReturnValues.Success, actual);
46+
Assert.AreEqual(0, numTestFailures);
4747
}
4848

4949
private static EExciserReturnValues RunExciserIntegrationTests(string fileExtension, string inputPath, string outputPath, ref int numTestFailures, ref int numTestCases)

ServerCodeExciserTest/ServerCodeExciserTest.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
54
<TargetFramework>net6.0</TargetFramework>
65
<Nullable>enable</Nullable>
76
<IsPackable>false</IsPackable>
87
</PropertyGroup>
98

9+
<ItemGroup>
10+
<PackageReference Include="MSTest" Version="3.11.1" />
11+
</ItemGroup>
12+
1013
<ItemGroup>
1114
<ProjectReference Include="..\ServerCodeExciser\ServerCodeExciser.csproj" />
1215
</ItemGroup>

0 commit comments

Comments
 (0)