Test-Driven Gamedev - testy automatyczne a tworzenie gier

35
TEST-DRIVEN GAMEDEV Konrad Gadzina Senior Software Engineer WWW.GANYMEDE.EU TESTY AUTOMATYCZNE A TWORZENIE GIER

Transcript of Test-Driven Gamedev - testy automatyczne a tworzenie gier

Page 1: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TEST-DRIVEN GAMEDEVKonrad Gadzina

Senior Software EngineerWWW.GANYMEDE.EU

TESTY AUTOMATYCZNE A TWORZENIE GIER

Page 2: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TO W GRY NIE WYSTARCZY GRAĆ?

1

Page 3: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TESTOWANIE MANUALNECo nam daje?

• sprawdzanie grywalności i ogólnego odbioru gry• wyłapywanie exploitów

Page 4: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TESTOWANIE MANUALNECzego nam nie daje?

• pewności przy wprowadzaniu sporych zmian• szybkiej informacji zwrotnej• całkowitej powtarzalności

Page 5: Test-Driven Gamedev - testy automatyczne a tworzenie gier

JAK AUTOMATYZOWAĆ TESTY?

2

Page 6: Test-Driven Gamedev - testy automatyczne a tworzenie gier

A TO NIE ROBOTA TESTERÓW?

Większość osób myśli, że testowanie to piaskownica testerów. Sami programiści lubią tak myśleć.

Page 7: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TYPY TESTÓW

Konwencje podziału są różne, jedna z popularnych:• jednostkowe• funkcjonalne• integracyjne

Page 8: Test-Driven Gamedev - testy automatyczne a tworzenie gier

Z CZYM DO CZEGO?

“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 9: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TESTY JEDNOSTKOWE

• sprawdzają poprawność poszczególnych elementów w izolacji

• wymuszają modularną architekturę• pisane z perspektywy programisty• nie sprawdzają interakcji

Page 10: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TESTY FUNKCJONALNE

• sprawdzają poprawność interakcji między różnymi elementami programu

• pisane z perspektywy użytkownika

Page 11: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TESTY INTEGRACYJNE

• sprawdzają poprawność komunikacji z zewnętrznymi systemami

• są testami funkcjonalnymi

Page 12: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TEST-DRIVEN DEVELOPMENTIdea

• pisanie testów jednostkowych przed napisaniem kodu, który ma byćtestowany

• pisanie tylko tyle, ile jest konieczne w danym momencie, ani linijki więcej

• bardzo krótkie iteracje

Page 13: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TEST-DRIVEN DEVELOPMENTRed-green-refactor mantra

1. Napisz test, który nie przejdzie2. Dopisz kod produkcyjny, by test

przeszedł3. Refaktoruj

Page 14: Test-Driven Gamedev - testy automatyczne a tworzenie gier

BEHAVIOUR-DRIVEN DEVELOPMENTZachowania

Tworzenie scenariuszy zachowań, które przekładają się na testy integracyjne.

Według niektórych „BDD is TDD done right”.

Page 15: Test-Driven Gamedev - testy automatyczne a tworzenie gier

BEHAVIOUR-DRIVEN DEVELOPMENTKomunikacja

Założeniem BDD jest zapewnienie dobrej komunikacji między zespołem developerskim a klientem.

Tworzy się DSL – Domain Specific Lanuage, używany w scenariuszach i rozumiany przez obie strony.

Page 16: Test-Driven Gamedev - testy automatyczne a tworzenie gier

TO CO Z TYMI GRAMI?

3

Page 17: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CZEMU NIE TESTUJEMYPozorna nieopłacalność testów

“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 18: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CZEMU NIE TESTUJEMYPotencjalne problemy z testowaniem

“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 19: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CZEMU NIE TESTUJEMY

Perspektywiczne myślenie oraz modularna architektura mogą rozwiązać wiele problemów.

Page 20: Test-Driven Gamedev - testy automatyczne a tworzenie gier

“WIELCY GRACZE” A TESTY

"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 21: Test-Driven Gamedev - testy automatyczne a tworzenie gier

“WIELCY GRACZE” A TESTY

"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 22: Test-Driven Gamedev - testy automatyczne a tworzenie gier

“WIELCY GRACZE” A TESTYOferty pracy w branżyUI / Scaleform Developer @ Rockstar:

“DESIRED● Working knowledge of C++.● (..)● Experience with UNIT testing.”

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

“Pluses● Experience with C++11● (..)● Experience designing and implementing unit tests“

Page 23: Test-Driven Gamedev - testy automatyczne a tworzenie gier

UNITY TEST TOOLS

Darmowe narzędzie rozwijane przez Unity. Ułatwia:

• testy jednostkowe

• testy integracyjne

Page 24: Test-Driven Gamedev - testy automatyczne a tworzenie gier

DEMO!

4

Page 25: Test-Driven Gamedev - testy automatyczne a tworzenie gier

YASICYet Another Space Ivaders Clone

• gra rekrutacyjna do Ganymede• JavaScript – Phaser + Jasmine• Behaviour-Driven Development

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

Page 26: Test-Driven Gamedev - testy automatyczne a tworzenie gier

JAK TDD WYCHODZI ZE STARCIA Z LEGACY CODE?

5

Page 27: Test-Driven Gamedev - testy automatyczne a tworzenie gier

DOBRZE, A TY?

Zmiany w starym kodzie, którego nie znamy są często ryzykowne. Wystąpienie regresji jest bardzo prawdopodobne, wydajność programistów jest niższa.

Page 28: Test-Driven Gamedev - testy automatyczne a tworzenie gier

EDIT AND PRAY VS COVER AND MODIFY

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

Page 29: Test-Driven Gamedev - testy automatyczne a tworzenie gier

ZMIANY W LEGACY CODESiatka bezpieczeństwa

1. Zidentyfikuj miejsca wymagające zmiany

2. Znajdź miejsca do testowania3. Rozbij zależności4. Napisz testy5. Dokonaj zmian i zrefaktoruj

Page 30: Test-Driven Gamedev - testy automatyczne a tworzenie gier

JAK WDROŻYĆ SIĘ W TDD?

6

Page 31: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CODING DOJO

Spotkanie, na którym grupa ludzi rozwiązuje problemy programistyczne z wykorzystaniem TDD.

Wyróżniamy:• Prepared Kata• Randori Kata

Page 32: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CODING DOJOPrepared Kata

• jedna osoba rozwiązuje cały problem• pozostali mogą sugerować kolejne testy• przyjaźniejsze przy pierwszym kontakcie z

TDD

Page 33: Test-Driven Gamedev - testy automatyczne a tworzenie gier

CODING DOJORandori Kata

• pair programming• zmiana w parze po pewnym czasie• „baby steps”

Page 34: Test-Driven Gamedev - testy automatyczne a tworzenie gier

PODSUMOWANIE

7

Page 35: Test-Driven Gamedev - testy automatyczne a tworzenie gier