Skip to content

Commit 60508ca

Browse files
committed
New Feature: Direct Agent Execution
1 parent 0fef407 commit 60508ca

14 files changed

+515
-8
lines changed

NUnitConsole.sln

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.agent.core.tests", "s
164164
EndProject
165165
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeExtensions", "src\TestData\FakeExtensions\FakeExtensions.csproj", "{608AA86D-4090-33CA-0031-BD324E5A766E}"
166166
EndProject
167+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DirectTestAgent", "src\NUnitCommon\DirectTestAgent\DirectTestAgent.csproj", "{0E415863-1621-41DB-9DB0-36B5664DFF35}"
168+
EndProject
167169
Global
168170
GlobalSection(SolutionConfigurationPlatforms) = preSolution
169171
Debug|Any CPU = Debug|Any CPU
@@ -290,6 +292,10 @@ Global
290292
{608AA86D-4090-33CA-0031-BD324E5A766E}.Debug|Any CPU.Build.0 = Debug|Any CPU
291293
{608AA86D-4090-33CA-0031-BD324E5A766E}.Release|Any CPU.ActiveCfg = Release|Any CPU
292294
{608AA86D-4090-33CA-0031-BD324E5A766E}.Release|Any CPU.Build.0 = Release|Any CPU
295+
{0E415863-1621-41DB-9DB0-36B5664DFF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
296+
{0E415863-1621-41DB-9DB0-36B5664DFF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
297+
{0E415863-1621-41DB-9DB0-36B5664DFF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
298+
{0E415863-1621-41DB-9DB0-36B5664DFF35}.Release|Any CPU.Build.0 = Release|Any CPU
293299
EndGlobalSection
294300
GlobalSection(SolutionProperties) = preSolution
295301
HideSolutionNode = FALSE
@@ -336,6 +342,7 @@ Global
336342
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
337343
{89258A3E-5B62-487A-9AE7-D7672CBF61F1} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
338344
{608AA86D-4090-33CA-0031-BD324E5A766E} = {37D508B2-91E0-4B32-869B-DFF9E68EA213}
345+
{0E415863-1621-41DB-9DB0-36B5664DFF35} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
339346
EndGlobalSection
340347
GlobalSection(ExtensibilityGlobals) = postSolution
341348
SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2+
3+
namespace NUnit.Agents
4+
{
5+
public class DirectTestAgent : NUnitAgent<DirectTestAgent>
6+
{
7+
public static void Main(string[] args)
8+
{
9+
Execute(args);
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RootNamespace>NUnit.Agents.Agents</RootNamespace>
5+
<OutputType>Exe</OutputType>
6+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
7+
<OutputPath>..\..\bin\$(Configuration)\direct-test-agent\</OutputPath>
8+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
9+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\NUnitEngine\nunit.engine.api\nunit.engine.api.csproj" />
14+
<ProjectReference Include="..\nunit.agent.core\nunit.agent.core.csproj" />
15+
<ProjectReference Include="..\nunit.extensibility\nunit.extensibility.csproj" />
16+
</ItemGroup>
17+
18+
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
19+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
20+
</ItemGroup>
21+
22+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using NUnit.Framework;
10+
using NUnit.TestData.Assemblies;
11+
12+
namespace NUnit.Agents
13+
{
14+
public class AgentDirectRunnerTests
15+
{
16+
[Test]
17+
public void RunAgentDirectly()
18+
{
19+
RunTestUnderTestBed(typeof(MockAssembly).Assembly.Location);
20+
}
21+
22+
private void RunTestUnderTestBed(string testAssembly)
23+
{
24+
string agentAssembly = typeof(DirectTestAgent).Assembly.Location;
25+
26+
#if NETFRAMEWORK
27+
string agentExe = agentAssembly;
28+
#else
29+
string agentExe = Path.ChangeExtension(agentAssembly, ".exe");
30+
#endif
31+
32+
var startInfo = new ProcessStartInfo(agentExe);
33+
startInfo.Arguments = testAssembly;
34+
startInfo.RedirectStandardOutput = true;
35+
startInfo.UseShellExecute = false;
36+
37+
Process? process = Process.Start(startInfo);
38+
39+
if (process != null)
40+
{
41+
process.WaitForExit();
42+
43+
string output = process.StandardOutput.ReadToEnd();
44+
int index = output.IndexOf("Test Run Summary");
45+
if (index > 0)
46+
output = output.Substring(index);
47+
48+
Console.WriteLine(output);
49+
Console.WriteLine($"Agent process exited with rc={process.ExitCode}");
50+
51+
if (index < 0)
52+
Assert.Fail("No Summary Report found");
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<appSettings>
4+
<add key="test.setting" value="54321"/>
5+
</appSettings>
6+
</configuration>

src/NUnitCommon/nunit.agent.core.tests/Drivers/DriverServiceTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public void CorrectDriverIsUsed(string fileName, bool skipNonTestAssemblies, Typ
3838
new TestCaseData("mock-assembly.pdb", true, typeof(InvalidAssemblyFrameworkDriver)),
3939
new TestCaseData("junk.dll", false, typeof(InvalidAssemblyFrameworkDriver)),
4040
new TestCaseData("junk.dll", true, typeof(InvalidAssemblyFrameworkDriver)),
41-
new TestCaseData("nunit.engine.core.dll", false, typeof(InvalidAssemblyFrameworkDriver)),
42-
new TestCaseData("nunit.engine.core.dll", true, typeof(SkippedAssemblyFrameworkDriver))
41+
new TestCaseData("nunit.agent.core.dll", false, typeof(InvalidAssemblyFrameworkDriver)),
42+
new TestCaseData("nunit.agent.core.dll", true, typeof(SkippedAssemblyFrameworkDriver))
4343
};
4444

4545
[Test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2+
3+
using System.Reflection;
4+
using NUnitLite;
5+
6+
namespace NUnit.Engine.Tests
7+
{
8+
class Program
9+
{
10+
static int Main(string[] args)
11+
{
12+
return new TextRunner(typeof(Program).Assembly).Execute(args);
13+
}
14+
}
15+
}

src/NUnitCommon/nunit.agent.core.tests/Runners/DomainManagerStaticTests.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ public static class DomainManagerStaticTests
1616
static string path2 = TestPath("/test/bin/debug/test2.dll");
1717
static string path3 = TestPath("/test/utils/test3.dll");
1818

19-
#if NETFRAMEWORK
20-
const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.exe.config";
21-
#else
22-
const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.dll.config";
23-
#endif
19+
const string STANDARD_CONFIG_FILE = "nunit.agent.core.tests.exe.config";
2420
const string ALTERNATE_CONFIG_FILE = "alt.config";
2521

2622
[Test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<appSettings>
4+
<add key="test.setting" value="Alternate config used"/>
5+
</appSettings>
6+
</configuration>

src/NUnitCommon/nunit.agent.core.tests/nunit.agent.core.tests.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net462;net8.0</TargetFrameworks>
5+
<OutputType>Exe</OutputType>
56
<ExposedInternals>true</ExposedInternals>
67
</PropertyGroup>
78

@@ -28,6 +29,7 @@
2829

2930
<ItemGroup>
3031
<ProjectReference Include="..\..\TestData\mock-assembly\mock-assembly.csproj" />
32+
<ProjectReference Include="..\DirectTestAgent\DirectTestAgent.csproj" />
3133
<ProjectReference Include="..\nunit.agent.core\nunit.agent.core.csproj" />
3234
<ProjectReference Include="..\nunit.common\nunit.common.csproj" />
3335
</ItemGroup>

0 commit comments

Comments
 (0)