test-driven gamedev tests automation and game development team leader / senior software engineer ...

52
TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer WWW.GANYMEDE.EU Konrad Gadzina

Upload: ross-wilkins

Post on 20-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TEST-DRIVEN GAMEDEVTESTS AUTOMATION AND GAME DEVELOPMENT

Team Leader / Senior Software EngineerWWW.GANYMEDE.EU

Konrad Gadzina

Page 2: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

AGENDA

1. Why to automate tests?2. How to do it?3. Automated testing in

games4. Small demo5. TDD and legacy code6. Real-life working

experience7. How to learn?

Page 3: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

THAT’S NOT THE SLIDE YOU’RE LOOKING FOR

a.k.a. why am I here?

0

Page 4: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WAIT, ISN’T IT ENOUGH TO PLAY THE GAME?

1

Page 5: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WAIT, ISN’T IT ENOUGH TO PLAY THE GAME?

1

Page 6: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

MANUAL TESTING

What does it give us?

• checking playability and game feel

• finding exploits

Page 7: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

MANUAL TESTING

What does it not give us?

• certainty while developing big changes

• quick feedback• full repeatability

Page 8: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

MANUAL TESTING

Like board games vs computer games• in computer games you don’t have

to remember the rules• you can assume that they will be

predictable and repeatable• but, still, they cannot replace board

games – they are different

Page 9: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

OK, AUTOMATE TESTS, BUT HOW?

2

Page 10: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WAIT, ISN’T IT A TESTER’S JOB?

Most people think that testing is only testers’ playground.Many programmers like to see it this wayThey don’t imagine how much they can do by themselves.

Page 11: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TYPES OF TESTS

There are many conventions, one of many popular divisions:• unit• functional• integration

Page 12: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WHAT TO USE?

“Unit tests tell a developer that the code is doing things right; functional tests tell a developer that the code is doing the right things.”

http://www.softwaretestingtricks.com/2007/01/unit-testing-versus-functional-tests.html

Page 13: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

UNIT TESTS

• check correctness of specific elements in isolation

• enforce modular architecture• are written from the

programmer’s perspective• don’t check interactions

Page 14: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

FUNCTIONAL TESTS

• check interactions between differents parts of the application

• written from the user’s perspective

Page 15: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

INTEGRATION TESTS

• check correctness of communication with external systems

• are functional tests

Page 16: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TEST-DRIVEN DEVELOPMENT

Idea

• writing unit tests before writing production code

• writing as much as needed at the moment, nothing more

• very short iterations

Page 17: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TEST-DRIVEN DEVELOPMENT

Red-green-refactor mantra

1. Write test that fails2. Write production code to make

test pass3. Refactor

Page 18: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

BEHAVIOUR-DRIVEN DEVELOPMENT

Behaviours

Creating behaviour scenarios that became integration tests.

Some say that „BDD is TDD done right”.

Page 19: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

BEHAVIOUR-DRIVEN DEVELOPMENT

Communication

Core principle of BDD is creating a good communication between the dev team and the customer.

DSL is created – Domain Specific Language, that’s used in scenarios and is understable by both sides.

Page 20: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

SO, WHAT’S WITH THOSE GAMES, AGAIN?

3

Page 21: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WHY WE DON’T TEST?

Seeming unprofitability of tests

“However, for most game code that is written once and then discarded, unit tests generally do not make sense. The cost to hire an room full of QA testers to verify everything at the end of the project is often less than the cost to create the automated tests.”

http://www.gamedev.net/topic/648772-unit-testing-ftw/

Page 22: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WHY WE DON’T TEST?

Potential problems with testing

“It is hard to write unit tests for code that is non-deterministic. If you have code involving random numbers, you won't be able to write a unit test that asserts an expected result.”

http://programmers.stackexchange.com/questions/250449/test-driven-development-for-complex-games

Page 23: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WHY WE DON’T TEST?

Why do you have problems?

Long-range thinking and modular architecture can solve many problems.

Page 24: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

„BIG PLAYERS” AND TESTS

What great people say

"Whenever I come across a finicky looking bit of code now, I split it out into a separate pure function and write tests for it. Frighteningly, I often find something wrong in these cases, which means I'm probably not casting a wide enough net."

John Carmackhttp://gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php

Page 25: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

„BIG PLAYERS” AND TESTS

What great people say

"I have never done real TDD. I make the excuse that real time stuff is harder to TDD for, but I know I don't do enough test."

John Carmackhttps://twitter.com/id_aa_carmack/status/459112425833246720

Page 26: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

„BIG PLAYERS” AND TESTS

Job offers in games

UI / Scaleform Developer @ Rockstar:

“DESIRED (..)

● Experience with UNIT testing.”

Senior Software Engineer, C++ - Infrastructure @ Blizzard:

“Pluses (..)

● Experience designing and implementing unit tests“

Page 27: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

UNITY TEST TOOLS

Free tools developed by Unity itself.It allows you to do:• unit tests• integration tests

http://u3d.as/65h

Page 28: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TALK IS CHEAP, SHOW ME THE CODE!

4

Page 29: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

YASIC

Yet Another Space Invaders Clone

• recruitment game for Ganymede• JavaScript – Phaser + Jasmine• Behaviour-Driven Development

http://fenixb3.github.io/YASIC/

Page 30: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TDG PROJECT

Test-Driven Gamedev Project

• project started after workshops on Codepot conference

• Unity3D + Unity Test Tools• Test-Driven Development

https://github.com/FeniXb3/Test-Driven-Gamedev

Page 31: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

WELL, HOW DOES TDD WORK WITH LEGACY CODE?

5

Page 32: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

PRETTY AWESOME, AND YOU?

Changes in old code that we don’t even know are almost always risky.Regression is highly possible to occur, productivity of developers is lower.

Page 33: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

EDIT AND PRAY VS COVER AND MODIFY

“To me, legacy code is simply code without tests.”

Michael C. FeathersWorking Effectively with Legacy Code

Page 34: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

CHANGES IN LEGACY CODE

The safety net

1. Identify parts that have to be changed

2. Find place to put your tests3. Break dependencies4. Write tests5. Perform the change and refactor

Page 35: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

YOU SAY GANYMEDE DOES IT?

6

Page 36: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

YES, WE DOBut there are still some checkpoints before the final boss

Page 37: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE

What technology brings us

ActionScript:• FlexUnit + Mockolate• Made more friendly with

RobotlegsC++:• Catch or BanditUnity:• Unity Test Tools

Page 38: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE

What problems do we have?

ActionScript:• FlexUnit can’t run without

graphics• …so you can’t use it on CI server

in headless mode• and, well, it is Flash…

Page 39: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE

What problems do we have?

C++:• code we have in C++ is not new• …and it does not have any tests• …and many parts of it have

never heard of loose coupling

Page 40: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE

What problems do we have?

Unity:• you can’t unit test

MonoBehaviours directly• there are sealed classes hard to

mock• build on Jenkins running on Mac

fails when test uses NSubstitute• AssertComponent doesn’t work

on prefabs

Page 41: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE - UNITY

How to do it

To make yout code testable you can use:• MVC pattern• Humble Object Pattern

Page 42: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE - UNITY

How to do it – Humble Object Pattern

• create class that handles logic

• create tests for it• use its methods one-to-one

in MonoBehaviour• http://blogs.unity3d.com/2014/06/03/unit-te

sting-part-2-unit-testing-monobehaviours/

Page 43: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE - UNITY

How to do it – MVC

We use StrangeIoC – dependency injection and MVCS framework.It forces modular architecture.Ergo, it makes your code easier to test.http://strangeioc.github.io/strangeioc/

Page 44: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE - UNITY

How we do it – the whole picture

What we exactly do:• we create commands that are

triggered by signals• we test expected behaviour of

commands• we test services that are used

by commands

Page 45: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

TESTING IN GANYMEDE - UNITY

How we do it – the whole picture

What we exactly do - continued:• we mock boundaries where

possible• we create integration tests

when needed• we have testers who can catch

bugs like multitouching where it should not be avaible

Page 46: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

HOW TO DIG INTO TDD?

7

Page 47: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

CODING DOJO

Meeting where group of people solve small programming problems (kata) using TDD.

There are two types of kata:• Prepared Kata• Randori Kata

Page 48: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

CODING DOJO

Prepared Kata

• one person solve the whole problem

• the rest can suggest next tests• more friendly if that’s a first

contact with TDD

Page 49: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

CODING DOJO

Randori Kata

• pair programming• change in pair after predefined

time• „baby steps”

Page 50: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

OK, SUM IT UP!

Page 51: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

SUMMARY

• writing tests can take more time on development but less time on fixing

• TDD enforce you to not write useless code

• tests are your regression safety net• there are game companies who do it• we do it at Ganymede – it works!

Page 52: TEST-DRIVEN GAMEDEV TESTS AUTOMATION AND GAME DEVELOPMENT Team Leader / Senior Software Engineer  Konrad Gadzina

www.ganymede.euwww.gamedesire.comwww.ganymedeacademy.com

[email protected]

THANKS FOR YOUR ATTENTION

@fenixb3