Improve integration testing

This commit is contained in:
Pieter-Jan Briers
2019-06-29 01:58:16 +02:00
parent e8498d1bb2
commit f97977323a
12 changed files with 177 additions and 20 deletions

View File

@@ -0,0 +1,57 @@
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Enums;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.UnitTesting;
namespace Content.IntegrationTests
{
[TestFixture]
public class ConnectTest : ContentIntegrationTest
{
[Test]
public async Task TestConnect()
{
var client = StartClient();
var server = StartServer();
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
// Connect.
client.SetConnectTarget(server);
client.Post(() => IoCManager.Resolve<IClientNetManager>().ClientConnect(null, 0, null));
// Run some ticks for the handshake to complete and such.
for (var i = 0; i < 10; i++)
{
server.RunTicks(1);
await server.WaitIdleAsync();
client.RunTicks(1);
await client.WaitIdleAsync();
}
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
// Basic checks to ensure that they're connected and data got replicated.
var playerManager = server.ResolveDependency<IPlayerManager>();
Assert.That(playerManager.PlayerCount, Is.EqualTo(1));
Assert.That(playerManager.GetAllPlayers().First().Status, Is.EqualTo(SessionStatus.InGame));
var clEntityManager = client.ResolveDependency<IEntityManager>();
var svEntityManager = server.ResolveDependency<IEntityManager>();
var lastSvEntity = svEntityManager.GetEntities().Last();
var lastClEntity = clEntityManager.GetEntity(lastSvEntity.Uid);
Assert.That(lastClEntity.Transform.GridPosition, Is.EqualTo(lastSvEntity.Transform.GridPosition));
}
}
}

View File

@@ -7,19 +7,19 @@
<Platforms>x86;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Content.Client\Content.Client.csproj"/>
<ProjectReference Include="..\Content.Server\Content.Server.csproj"/>
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj"/>
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj"/>
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj"/>
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj"/>
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj"/>
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj"/>
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj"/>
<ProjectReference Include="..\Content.Client\Content.Client.csproj" />
<ProjectReference Include="..\Content.Server\Content.Server.csproj" />
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,27 @@
using Content.Client;
using Content.Client.Interfaces.Parallax;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.UnitTesting;
namespace Content.IntegrationTests
{
public abstract class ContentIntegrationTest : RobustIntegrationTest
{
protected override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null)
{
options = options ?? new ClientIntegrationOptions();
options.BeforeStart += () =>
{
IoCManager.Resolve<IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks
{
ClientBeforeIoC = () =>
{
IoCManager.Register<IParallaxManager, DummyParallaxManager>(true);
}
});
};
return base.StartClient(options);
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using Content.Client.Interfaces.Parallax;
using Robust.Client.Graphics;
namespace Content.IntegrationTests
{
public sealed class DummyParallaxManager : IParallaxManager
{
public event Action<Texture> OnTextureLoaded
{
add
{
}
remove
{
}
}
public Texture ParallaxTexture => null;
public void LoadParallax()
{
}
}
}

View File

@@ -6,7 +6,7 @@ using Robust.UnitTesting;
namespace Content.IntegrationTests
{
[TestFixture]
public class StartTest : RobustIntegrationTest
public class StartTest : ContentIntegrationTest
{
/// <summary>
/// Test that the server starts.
@@ -15,8 +15,6 @@ namespace Content.IntegrationTests
public async Task TestServerStart()
{
var server = StartServer();
await server.WaitIdleAsync();
Assert.That(server.IsAlive);
server.RunTicks(5);
await server.WaitIdleAsync();
Assert.That(server.IsAlive);
@@ -25,7 +23,6 @@ namespace Content.IntegrationTests
server.Stop();
await server.WaitIdleAsync();
Assert.That(!server.IsAlive);
Assert.That(server.UnhandledException, Is.Null);
}
/// <summary>