SlideShare a Scribd company logo
Game Programming
Automated Testing in Games
Nick Prühs
Objectives
• To learn how to properly set up automated testing for your games
• To get an overview of common unit testing frameworks and tools
2 / 49
Unit Testing
• Method by which individual units of source code are tested to
determine if they are fit for use
• Unit of source code is the smallest testable part of an application
(e.g. method)
• Created by programmers during the development process
• Usually split up into three parts:
▪ Arrange
▪ Act
▪ Assert
3 / 49
Unit Testing
• Ideally, each test case is independent from the others
• Substitutes such as mocks can be used to assist testing a module in
isolation (e.g. database, mails)
• Can be implemented as part of automated builds
4 / 49
Unit Testing with NUnit
• Unit Testing framework for all .NET languages
• Initially ported from JUnit
• Written entirely in C#
• Stand-alone tools and R# integration
5 / 49
Setting up NUnit
1. Add new Class Library project to the solution.
2. Add reference to bin/framework/nunit.framework.dll.
6 / 49
NUnit Test Class Design
• Public
• Default constructor
7 / 49
NUnit Test Method Design
• [Test] attribute
• Return void
• No parameters
8 / 49
NUnit Test Example
C#
9 / 49
namespace LevelEditor.Tests
{
using LevelEditor.Model;
using NUnit.Framework;
public class MapTest
{
[Test]
public void TestMapConstructor()
{
// Arrange.
const int Width = 32;
const int Height = 16;
// Act.
Map map = new Map(Width, Height);
// Assert.
Assert.AreEqual(Width, map.Width);
Assert.AreEqual(Height, map.Height);
}
}
}
NUnit Assertions
• AreEqual, AreNotEqual
• AreSame, AreNotSame
• IsTrue, IsFalse
• Greater, GreaterOrEqual
• Less, LessOrEqual
• IsEmpty, IsNotEmpty
• IsNull, IsNotNull
• Contains
• Fail, Inconclusive
10 / 49
Expected Exceptions
C#
11 / 49
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestNegativeWidth()
{
Map map = new Map(-10, 20);
}
SetUp and TearDown
C#
12 / 49
public class MapTest
{
private const int Height = 16;
private const int Width = 32;
private Map map;
[SetUp]
public void SetUp()
{
this.map = new Map(Width, Height);
}
[Test]
public void TestTileIndexer()
{
// Arrange.
const int X = 1;
const int Y = 2;
// Act.
var mapTile = new MapTile(X, Y, "Desert");
this.map[X, Y] = mapTile;
// Assert.
Assert.AreEqual(mapTile, this.map[X, Y]);
}
}
Hint
Override Equals in types whose
objects you need to compare!
13 / 49
NUnit Test Tool
14 / 49
NUnit Console
Console Output
15 / 49
D:DevRepositoriesSAE-ToolDevelopmentVendorNUnit-2.6.3bin>nunit-console-x86.exe
......SourceLevelEditor.TestsbinDebugLevelEditor.Tests.dll
NUnit-Console version 2.6.3.13283
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.2.9200.0
CLR Version: 2.0.50727.7905 ( Net 3.5 )
ProcessModel: Default DomainUsage: Single
Execution Runtime: net-3.5
...
Tests run: 3, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.046059608766156 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
NUnit & Visual Studio
16 / 49
NUnit & Visual Studio
17 / 49
Advantages of Unit Testing
✓ Finds problems early
▪ Test Driven Development
✓ Facilitates changes
▪ Can be run before each commit or build
▪ In combination with source control, can identify the revision (and
originator) that broke the code
18 / 49
Limits of Unit Testing
• Won’t catch every error in the program
• Won’t catch integration errors
• Combinatorial problem
▪ Every boolean decision statement requires at least two tests
• Can’t test non-deterministic or concurrency problems
19 / 49
Limits of Unit Testing
• Setting up realistic and useful tests is a challenge
• Test case failures need to be reviewed daily and addressed
immediately
• Embedded system software presents a unique challenge
▪ Software is being developed on a different platform than the one
it will eventually run on
20 / 49
Test Driven Development
1. Write an (initially failing) automated test case that defines a desired
improvement or new function.
2. Produce the minimum amount of code required to pass that test.
3. Refactor the new code to acceptable standards.
21 / 49
Advantages of TDD
✓ Client-first development
✓ Taking small steps
✓ All written code is covered by at least one test
✓ Can lead to more modularized code
22 / 49
Limits of TDD
• Support of the entire team is essential
• Test are typically created by the developer who is writing the code
being tested, and may therefore share the same blind spots with the
code
• Maintenance overhead
23 / 49
Unity Test Tools
• Released by Unity in December 2013
• Partly integrated since Unity 5.3
• Completely open-source
• Available on the Asset Store and Bitbucket
• Based on NUnit
24 / 49
Unity Test Tools
• Unit tests are discovered using reflections
• Can be run automatically on recompile
26 / 49
Unity Test Tools
27 / 49
Unity NUnit Test Runner Window
Unity Test Tools
• Integration tests allow testing integration of components, game
objects and assets
• Each test suite is a separate scene containing a game object with a
TestRunner attached
• Each test is a separate game object with a TestComponent attached
▪ Everything beneath that object in the hierarchy is considered to
belong to that test
• The CallTesting behaviour can modify the test result without having
to actually write additional code
28 / 49
Unity Test Tools
When you run the tests, the following steps are performed, in order:
1. Play mode is enabled.
2. The first or next test object is activated.
3. Wait until the test has finished (or a timeout has occurred).
4. The current active test gets deactivated.
5. If there are more tests in the queue, go to step 2.
6. Report results and finish test run.
29 / 49
Unity Test Tools
30 / 49Unity Integration Test Scene
Unity Test Tools
• Assertions check invariants – conditions you expect to be always
true
• You can specify when to check these conditions
• If any assertion fails, an exception is thrown
• You can automatically cause the game in that case by enabling
Error pause in the Unity console window
31 / 49
Unity Test Tools
32 / 49
Unity Assertion Component
Unity Test Tools
Just like with NUnit, Unity integration tests can be run from command
line:
"C:Program Files (x86)UnityEditorUnity.exe“
–batchmode
-projectPath D:TempUnityTest
-executeMethod UnityTest.Batch.RunIntegrationTests
-testscenes=NpruehsScene
-targetPlatform=StandaloneWindows
-resultsFileDirectory=D:TempResults
33 / 49
NSubstitute
• Creates substitutes for interfaces
• Saves you from having to use stubs, mocks, spies, test doubles
34 / 49
public interface ICalculator
{
int Add(int a, int b);
}
NSubstitute
• Creates substitutes for interfaces
• Saves you from having to use stubs, mocks, spies, test doubles
35 / 49
ICalculator calculator = Substitute.For<ICalculator>();
NSubstitute
• Allows you set up return values to method calls.
• Great for mocking database connections or email plugins.
36 / 49
calculator.Add(1, 2).Returns(3);
37 / 49
Unit Testing in C++
• googletest is a platform-independent framework for writing C++ tests
• Used for a variety of Google projects, including Chromium and
Google Protocol Buffers
• googlemock allows you to write and mock C++ mock classes
38 / 49
Unit Testing in C++
1. Create a new Win32 console application.
2. Add the projects you want to test to the additional include
directories.
3. Add the gtest root folder and gtest-a.b.c/include folder to the
additional include directories.
4. In your test source file, #include "src/gtest-all.cc“.
5. Provide a main entry point like this:
39 / 49
GTEST_API_ int main(int argc, char
**argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Unit Testing in C++
Test method signatures are automatically generated by the TEST
macro:
40 / 49
TEST(TestSuiteName, TestName)
{
// Arrange.
// Act.
// Assert.
}
Unit Testing in C++
Assertions are made using macros as well.
41 / 49
TEST(TestArithmetic, TestAdd)
{
// Arrange.
auto i = 3;
auto j = 4;
// Act.
auto k = i + j;
// Assert.
EXPECT_EQ(7, k);
}
Unit Testing in C++
Run the tests by just starting the console application…
42 / 49
Unit Testing in C++
… or by using the UI of gtest-gbar.
43 / 49
Unit Testing in C++
googlemock provides macros for mocking methods.
44 / 49
#pragma once
#include "gmock/gmock.h"
class ICalculator
{
public:
virtual int Add(int x, int y) = 0;
};
class MockCalculator : public ICalculator
{
public:
MOCK_METHOD2(Add, int(int x, int y));
};
Unit Testing in C++
Just like NSubstitute, it allows you to specify results:
45 / 49
#include "src/gtest-all.cc"
#include "src/gmock-all.cc"
#include "MockCalculator.h"
using ::testing::Return;
TEST(TestArithmetic, TestCalculator)
{
// Arrange.
MockCalculator calculator;
EXPECT_CALL(calculator, Add(3, 4))
.WillRepeatedly(Return(7));
// Act.
auto sum = calculator.Add(3, 4);
// Assert.
EXPECT_EQ(7, sum);
}
Unit Testing in UE 4
Unreal Engine 4 defines unit tests with macros, too:
46 / 49
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FSetResTest, "Windows.SetResolution", ATF_Game)
bool FSetResTest::RunTest(const FString& Parameters)
{
FString MapName = TEXT("AutomationTest");
FEngineAutomationTestUtilities::LoadMap(MapName);
int32 ResX = GSystemSettings.ResX;
int32 ResY = GSystemSettings.ResY;
FString RestoreResolutionString =
FString::Printf(TEXT("setres %dx%d"), ResX, ResY);
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f));
ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(TEXT("setres 640x480")));
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f));
ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(RestoreResolutionString));
return true;
}
Unit Testing in UE 4
Tests can be run from the Unreal Frontend:
47 / 49
References
• Wikipedia. Unit testing. http://en.wikipedia.org/wiki/Unit_testing, April 25, 2017.
• Poole. NUnit Quick Start. http://www.nunit.org/index.php?p=quickStart&r=2.6.4, 2015.
• Wikipedia. Test-driven development. http://en.wikipedia.org/wiki/Test-driven_development, April
21, 2017.
• Petersen. Unity Test Tools Released. http://blogs.unity3d.com/2013/12/18/unity-test-tools-
released/, December 18, 2013.
• Unity Technologies. Unity Test Tools. https://bitbucket.org/Unity-Technologies/unitytesttools, March
9, 2017.
• NSubstitute. NSubstitute. http://nsubstitute.github.io/help/getting-started/, May 2017.
• Google. Google C++ Testing Framework. https://code.google.com/p/googletest/, May 19, 2017.
• Google. Google Test UI. https://code.google.com/p/gtest-gbar/, May 2, 2017.
• Epic Games. Unreal Engine Automation Technical Guide.
https://docs.unrealengine.com/latest/INT/Programming/Automation/TechnicalGuide/, May 2017.
• Epic Games. Unreal Engine Automation User Guide.
https://docs.unrealengine.com/latest/INT/Programming/Automation/UserGuide/, May 2017.
48 / 49
Thank you!
http://www.npruehs.de
https://github.com/npruehs
@npruehs
nick.pruehs@daedalic.com
5 Minute Review Session
• What are unit tests?
• What are the main advantages of unit testing?
• What are the most important limits of unit tests?
• Explain the process of Test Driven Development!
• What are the upsides and downsides of TDD?
• What are integration tests?
• How do you test functionality that depends on external
communication (e.g. database, mails)?

More Related Content

What's hot

Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
Nick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
Nick Pruehs
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
Kevin Beeman
 
Introduction to Box2D Physics Engine
Introduction to Box2D Physics EngineIntroduction to Box2D Physics Engine
Introduction to Box2D Physics Engine
firstthumb
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
Luca Galli
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
rit2010
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
ICS
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
Lewis Brierley
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
Lewis Brierley
 
Database Management Assignment Help
Database Management Assignment Help Database Management Assignment Help
Database Management Assignment Help
Database Homework Help
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
Animesh Kumar
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programing
unihack
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
Arulalan T
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
 
Junit
JunitJunit
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
Greg.Helton
 
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
Concentrated Technology
 
eclipse
eclipseeclipse
eclipse
tvhung
 

What's hot (20)

Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
 
Introduction to Box2D Physics Engine
Introduction to Box2D Physics EngineIntroduction to Box2D Physics Engine
Introduction to Box2D Physics Engine
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
 
Database Management Assignment Help
Database Management Assignment Help Database Management Assignment Help
Database Management Assignment Help
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programing
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
Junit
JunitJunit
Junit
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
 
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
TechMentor Fall, 2011 - Packaging Software for Automated Deployment with Wind...
 
eclipse
eclipseeclipse
eclipse
 

Viewers also liked

Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git Flow
Nick Pruehs
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity Systems
Nick Pruehs
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - Localization
Nick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
Nick Pruehs
 
What Would Blizzard Do
What Would Blizzard DoWhat Would Blizzard Do
What Would Blizzard Do
Nick Pruehs
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - Git
Nick Pruehs
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
Nick Pruehs
 
Game Programming 11 - Game Physics
Game Programming 11 - Game PhysicsGame Programming 11 - Game Physics
Game Programming 11 - Game Physics
Nick Pruehs
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small Teams
Nick Pruehs
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
The hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testingThe hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testing
Rémy-Christophe Schermesser
 
Game Models - A Different Approach
Game Models - A Different ApproachGame Models - A Different Approach
Game Models - A Different Approach
Nick Pruehs
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity Systems
Nick Pruehs
 
Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015
Simon Schmid
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with Pony
Nick Pruehs
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016
Simon Schmid
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Simon Schmid
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
Nick Pruehs
 
User Testing Your Game
User Testing Your GameUser Testing Your Game
User Testing Your Game
UserTesting
 

Viewers also liked (19)

Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git Flow
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity Systems
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - Localization
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
 
What Would Blizzard Do
What Would Blizzard DoWhat Would Blizzard Do
What Would Blizzard Do
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - Git
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Game Programming 11 - Game Physics
Game Programming 11 - Game PhysicsGame Programming 11 - Game Physics
Game Programming 11 - Game Physics
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small Teams
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 
The hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testingThe hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testing
 
Game Models - A Different Approach
Game Models - A Different ApproachGame Models - A Different Approach
Game Models - A Different Approach
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity Systems
 
Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with Pony
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
 
User Testing Your Game
User Testing Your GameUser Testing Your Game
User Testing Your Game
 

Similar to Game Programming 06 - Automated Testing

N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
priya_trivedi
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
Ravikiran J
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
ssuserd0fdaa
 
Coded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui testCoded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui test
Omer Karpas
 
Tool Development 09 - Localization & Testing
Tool Development 09 - Localization & TestingTool Development 09 - Localization & Testing
Tool Development 09 - Localization & Testing
Nick Pruehs
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Anand Kumar Rajana
 
Unit Testing Using N Unit
Unit Testing Using N UnitUnit Testing Using N Unit
Unit Testing Using N Unit
Gaurav Arora
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
Anatoliy Okhotnikov
 
Unit testing in Unity
Unit testing in UnityUnit testing in Unity
Unit testing in Unity
Mikko McMenamin
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013
Svetlin Nakov
 
Unit testing by Svetlin Nakov
Unit testing by Svetlin NakovUnit testing by Svetlin Nakov
Unit testing by Svetlin Nakov
it-tour
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
Priya Sharma
 
Testing and QA Open Mic
Testing and QA Open MicTesting and QA Open Mic
Testing and QA Open Mic
Unity Technologies
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
Baskar K
 
X unit testing framework with c# and vs code
X unit testing framework with c# and vs codeX unit testing framework with c# and vs code
X unit testing framework with c# and vs code
Shashank Tiwari
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Flutter Agency
 
Junit 4.0
Junit 4.0Junit 4.0
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptx
skknowledge
 
Tutorial ranorex
Tutorial ranorexTutorial ranorex
Tutorial ranorex
radikalzen
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
Peter Kofler
 

Similar to Game Programming 06 - Automated Testing (20)

N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Coded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui testCoded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui test
 
Tool Development 09 - Localization & Testing
Tool Development 09 - Localization & TestingTool Development 09 - Localization & Testing
Tool Development 09 - Localization & Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing Using N Unit
Unit Testing Using N UnitUnit Testing Using N Unit
Unit Testing Using N Unit
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Unit testing in Unity
Unit testing in UnityUnit testing in Unity
Unit testing in Unity
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013
 
Unit testing by Svetlin Nakov
Unit testing by Svetlin NakovUnit testing by Svetlin Nakov
Unit testing by Svetlin Nakov
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
Testing and QA Open Mic
Testing and QA Open MicTesting and QA Open Mic
Testing and QA Open Mic
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
X unit testing framework with c# and vs code
X unit testing framework with c# and vs codeX unit testing framework with c# and vs code
X unit testing framework with c# and vs code
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptx
 
Tutorial ranorex
Tutorial ranorexTutorial ranorex
Tutorial ranorex
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 

More from Nick Pruehs

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Nick Pruehs
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
Nick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
Nick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
Nick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
Nick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
Nick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
Nick Pruehs
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
Nick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
Nick Pruehs
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
Nick Pruehs
 

More from Nick Pruehs (10)

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
 

Recently uploaded

Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 

Recently uploaded (20)

Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 

Game Programming 06 - Automated Testing

  • 1. Game Programming Automated Testing in Games Nick Prühs
  • 2. Objectives • To learn how to properly set up automated testing for your games • To get an overview of common unit testing frameworks and tools 2 / 49
  • 3. Unit Testing • Method by which individual units of source code are tested to determine if they are fit for use • Unit of source code is the smallest testable part of an application (e.g. method) • Created by programmers during the development process • Usually split up into three parts: ▪ Arrange ▪ Act ▪ Assert 3 / 49
  • 4. Unit Testing • Ideally, each test case is independent from the others • Substitutes such as mocks can be used to assist testing a module in isolation (e.g. database, mails) • Can be implemented as part of automated builds 4 / 49
  • 5. Unit Testing with NUnit • Unit Testing framework for all .NET languages • Initially ported from JUnit • Written entirely in C# • Stand-alone tools and R# integration 5 / 49
  • 6. Setting up NUnit 1. Add new Class Library project to the solution. 2. Add reference to bin/framework/nunit.framework.dll. 6 / 49
  • 7. NUnit Test Class Design • Public • Default constructor 7 / 49
  • 8. NUnit Test Method Design • [Test] attribute • Return void • No parameters 8 / 49
  • 9. NUnit Test Example C# 9 / 49 namespace LevelEditor.Tests { using LevelEditor.Model; using NUnit.Framework; public class MapTest { [Test] public void TestMapConstructor() { // Arrange. const int Width = 32; const int Height = 16; // Act. Map map = new Map(Width, Height); // Assert. Assert.AreEqual(Width, map.Width); Assert.AreEqual(Height, map.Height); } } }
  • 10. NUnit Assertions • AreEqual, AreNotEqual • AreSame, AreNotSame • IsTrue, IsFalse • Greater, GreaterOrEqual • Less, LessOrEqual • IsEmpty, IsNotEmpty • IsNull, IsNotNull • Contains • Fail, Inconclusive 10 / 49
  • 11. Expected Exceptions C# 11 / 49 [Test] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void TestNegativeWidth() { Map map = new Map(-10, 20); }
  • 12. SetUp and TearDown C# 12 / 49 public class MapTest { private const int Height = 16; private const int Width = 32; private Map map; [SetUp] public void SetUp() { this.map = new Map(Width, Height); } [Test] public void TestTileIndexer() { // Arrange. const int X = 1; const int Y = 2; // Act. var mapTile = new MapTile(X, Y, "Desert"); this.map[X, Y] = mapTile; // Assert. Assert.AreEqual(mapTile, this.map[X, Y]); } }
  • 13. Hint Override Equals in types whose objects you need to compare! 13 / 49
  • 15. NUnit Console Console Output 15 / 49 D:DevRepositoriesSAE-ToolDevelopmentVendorNUnit-2.6.3bin>nunit-console-x86.exe ......SourceLevelEditor.TestsbinDebugLevelEditor.Tests.dll NUnit-Console version 2.6.3.13283 Copyright (C) 2002-2012 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved. Runtime Environment - OS Version: Microsoft Windows NT 6.2.9200.0 CLR Version: 2.0.50727.7905 ( Net 3.5 ) ProcessModel: Default DomainUsage: Single Execution Runtime: net-3.5 ... Tests run: 3, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.046059608766156 seconds Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
  • 16. NUnit & Visual Studio 16 / 49
  • 17. NUnit & Visual Studio 17 / 49
  • 18. Advantages of Unit Testing ✓ Finds problems early ▪ Test Driven Development ✓ Facilitates changes ▪ Can be run before each commit or build ▪ In combination with source control, can identify the revision (and originator) that broke the code 18 / 49
  • 19. Limits of Unit Testing • Won’t catch every error in the program • Won’t catch integration errors • Combinatorial problem ▪ Every boolean decision statement requires at least two tests • Can’t test non-deterministic or concurrency problems 19 / 49
  • 20. Limits of Unit Testing • Setting up realistic and useful tests is a challenge • Test case failures need to be reviewed daily and addressed immediately • Embedded system software presents a unique challenge ▪ Software is being developed on a different platform than the one it will eventually run on 20 / 49
  • 21. Test Driven Development 1. Write an (initially failing) automated test case that defines a desired improvement or new function. 2. Produce the minimum amount of code required to pass that test. 3. Refactor the new code to acceptable standards. 21 / 49
  • 22. Advantages of TDD ✓ Client-first development ✓ Taking small steps ✓ All written code is covered by at least one test ✓ Can lead to more modularized code 22 / 49
  • 23. Limits of TDD • Support of the entire team is essential • Test are typically created by the developer who is writing the code being tested, and may therefore share the same blind spots with the code • Maintenance overhead 23 / 49
  • 24. Unity Test Tools • Released by Unity in December 2013 • Partly integrated since Unity 5.3 • Completely open-source • Available on the Asset Store and Bitbucket • Based on NUnit 24 / 49
  • 25. Unity Test Tools • Unit tests are discovered using reflections • Can be run automatically on recompile 26 / 49
  • 26. Unity Test Tools 27 / 49 Unity NUnit Test Runner Window
  • 27. Unity Test Tools • Integration tests allow testing integration of components, game objects and assets • Each test suite is a separate scene containing a game object with a TestRunner attached • Each test is a separate game object with a TestComponent attached ▪ Everything beneath that object in the hierarchy is considered to belong to that test • The CallTesting behaviour can modify the test result without having to actually write additional code 28 / 49
  • 28. Unity Test Tools When you run the tests, the following steps are performed, in order: 1. Play mode is enabled. 2. The first or next test object is activated. 3. Wait until the test has finished (or a timeout has occurred). 4. The current active test gets deactivated. 5. If there are more tests in the queue, go to step 2. 6. Report results and finish test run. 29 / 49
  • 29. Unity Test Tools 30 / 49Unity Integration Test Scene
  • 30. Unity Test Tools • Assertions check invariants – conditions you expect to be always true • You can specify when to check these conditions • If any assertion fails, an exception is thrown • You can automatically cause the game in that case by enabling Error pause in the Unity console window 31 / 49
  • 31. Unity Test Tools 32 / 49 Unity Assertion Component
  • 32. Unity Test Tools Just like with NUnit, Unity integration tests can be run from command line: "C:Program Files (x86)UnityEditorUnity.exe“ –batchmode -projectPath D:TempUnityTest -executeMethod UnityTest.Batch.RunIntegrationTests -testscenes=NpruehsScene -targetPlatform=StandaloneWindows -resultsFileDirectory=D:TempResults 33 / 49
  • 33. NSubstitute • Creates substitutes for interfaces • Saves you from having to use stubs, mocks, spies, test doubles 34 / 49 public interface ICalculator { int Add(int a, int b); }
  • 34. NSubstitute • Creates substitutes for interfaces • Saves you from having to use stubs, mocks, spies, test doubles 35 / 49 ICalculator calculator = Substitute.For<ICalculator>();
  • 35. NSubstitute • Allows you set up return values to method calls. • Great for mocking database connections or email plugins. 36 / 49 calculator.Add(1, 2).Returns(3);
  • 37. Unit Testing in C++ • googletest is a platform-independent framework for writing C++ tests • Used for a variety of Google projects, including Chromium and Google Protocol Buffers • googlemock allows you to write and mock C++ mock classes 38 / 49
  • 38. Unit Testing in C++ 1. Create a new Win32 console application. 2. Add the projects you want to test to the additional include directories. 3. Add the gtest root folder and gtest-a.b.c/include folder to the additional include directories. 4. In your test source file, #include "src/gtest-all.cc“. 5. Provide a main entry point like this: 39 / 49 GTEST_API_ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
  • 39. Unit Testing in C++ Test method signatures are automatically generated by the TEST macro: 40 / 49 TEST(TestSuiteName, TestName) { // Arrange. // Act. // Assert. }
  • 40. Unit Testing in C++ Assertions are made using macros as well. 41 / 49 TEST(TestArithmetic, TestAdd) { // Arrange. auto i = 3; auto j = 4; // Act. auto k = i + j; // Assert. EXPECT_EQ(7, k); }
  • 41. Unit Testing in C++ Run the tests by just starting the console application… 42 / 49
  • 42. Unit Testing in C++ … or by using the UI of gtest-gbar. 43 / 49
  • 43. Unit Testing in C++ googlemock provides macros for mocking methods. 44 / 49 #pragma once #include "gmock/gmock.h" class ICalculator { public: virtual int Add(int x, int y) = 0; }; class MockCalculator : public ICalculator { public: MOCK_METHOD2(Add, int(int x, int y)); };
  • 44. Unit Testing in C++ Just like NSubstitute, it allows you to specify results: 45 / 49 #include "src/gtest-all.cc" #include "src/gmock-all.cc" #include "MockCalculator.h" using ::testing::Return; TEST(TestArithmetic, TestCalculator) { // Arrange. MockCalculator calculator; EXPECT_CALL(calculator, Add(3, 4)) .WillRepeatedly(Return(7)); // Act. auto sum = calculator.Add(3, 4); // Assert. EXPECT_EQ(7, sum); }
  • 45. Unit Testing in UE 4 Unreal Engine 4 defines unit tests with macros, too: 46 / 49 IMPLEMENT_SIMPLE_AUTOMATION_TEST(FSetResTest, "Windows.SetResolution", ATF_Game) bool FSetResTest::RunTest(const FString& Parameters) { FString MapName = TEXT("AutomationTest"); FEngineAutomationTestUtilities::LoadMap(MapName); int32 ResX = GSystemSettings.ResX; int32 ResY = GSystemSettings.ResY; FString RestoreResolutionString = FString::Printf(TEXT("setres %dx%d"), ResX, ResY); ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f)); ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(TEXT("setres 640x480"))); ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f)); ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(RestoreResolutionString)); return true; }
  • 46. Unit Testing in UE 4 Tests can be run from the Unreal Frontend: 47 / 49
  • 47. References • Wikipedia. Unit testing. http://en.wikipedia.org/wiki/Unit_testing, April 25, 2017. • Poole. NUnit Quick Start. http://www.nunit.org/index.php?p=quickStart&r=2.6.4, 2015. • Wikipedia. Test-driven development. http://en.wikipedia.org/wiki/Test-driven_development, April 21, 2017. • Petersen. Unity Test Tools Released. http://blogs.unity3d.com/2013/12/18/unity-test-tools- released/, December 18, 2013. • Unity Technologies. Unity Test Tools. https://bitbucket.org/Unity-Technologies/unitytesttools, March 9, 2017. • NSubstitute. NSubstitute. http://nsubstitute.github.io/help/getting-started/, May 2017. • Google. Google C++ Testing Framework. https://code.google.com/p/googletest/, May 19, 2017. • Google. Google Test UI. https://code.google.com/p/gtest-gbar/, May 2, 2017. • Epic Games. Unreal Engine Automation Technical Guide. https://docs.unrealengine.com/latest/INT/Programming/Automation/TechnicalGuide/, May 2017. • Epic Games. Unreal Engine Automation User Guide. https://docs.unrealengine.com/latest/INT/Programming/Automation/UserGuide/, May 2017. 48 / 49
  • 49. 5 Minute Review Session • What are unit tests? • What are the main advantages of unit testing? • What are the most important limits of unit tests? • Explain the process of Test Driven Development! • What are the upsides and downsides of TDD? • What are integration tests? • How do you test functionality that depends on external communication (e.g. database, mails)?