test
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"displayName": "Exercise 16: Solution",
|
||||
"description": "In this section we will look at some ways of implementing custom NUnit attributes, which can be used to alter test execution.",
|
||||
"interactiveImport": true
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfaf7d304187cea42b3510fc315677fc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
public class MyClass
|
||||
{
|
||||
public bool DoSomething()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DoSomethingElse()
|
||||
{
|
||||
// here is a regression that somebody made. It seems slow
|
||||
Thread.Sleep(500);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d48d08174b4d40448b70e15aeb8158aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "MyGame_16s"
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96e81f7ce7a44c543a1b5ee9af8b46c9
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1b9fe390b8750240a2d247831bdf51e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,14 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal.Commands;
|
||||
|
||||
namespace Tests_16s
|
||||
{
|
||||
public class FasterThan500msAttribute : NUnitAttribute, IWrapTestMethod
|
||||
{
|
||||
public TestCommand Wrap(TestCommand command)
|
||||
{
|
||||
return new FasterThan500msCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e399d362d3ea4ff79a388d3d19ace176
|
||||
timeCreated: 1579980719
|
@@ -0,0 +1,32 @@
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using NUnit.Framework.Internal.Commands;
|
||||
|
||||
namespace Tests_16s
|
||||
{
|
||||
public class FasterThan500msCommand : TestCommand
|
||||
{
|
||||
private TestCommand innerCommand;
|
||||
|
||||
public FasterThan500msCommand(TestCommand command) : base(command.Test)
|
||||
{
|
||||
innerCommand = command;
|
||||
}
|
||||
|
||||
public override TestResult Execute(ITestExecutionContext context)
|
||||
{
|
||||
var stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
var result = innerCommand.Execute(context);
|
||||
stopWatch.Stop();
|
||||
|
||||
if (stopWatch.ElapsedMilliseconds > 500)
|
||||
{
|
||||
result.SetResult(ResultState.Failure, $"Test took {stopWatch.ElapsedMilliseconds} ms. That is longer than 500ms!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ed6e6fb8cf749d9addbb831fb335be9
|
||||
timeCreated: 1579980907
|
@@ -0,0 +1,29 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests_16s
|
||||
{
|
||||
public class MyClassTests
|
||||
{
|
||||
[Test]
|
||||
[FasterThan500ms]
|
||||
public void SomethingReturnsTrue()
|
||||
{
|
||||
var classUnderTest = new MyClass();
|
||||
|
||||
var result = classUnderTest.DoSomething();
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[FasterThan500ms]
|
||||
public void SomethingElseReturnsTrue()
|
||||
{
|
||||
var classUnderTest = new MyClass();
|
||||
|
||||
var result = classUnderTest.DoSomethingElse();
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c22c25b768201734197db84613b1751f
|
||||
timeCreated: 1579981391
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Tests_16s",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"MyGame_16s"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59f1827b0899bf94a978cb788593a672
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user