1 of 25

Getting Started In Unit Testing For Games

2 of 25

Getting Started In Unit Testing For Games

By Bernice Anne W. Chua

3 of 25

Getting Started In Unit Testing For Games

twitter.com/ChuaBernice�Slides available at BerniceChua.com

4 of 25

Getting Started In Unit Testing For Games

5 of 25

Getting Started In Unit Testing For Games

6 of 25

Getting Started In Unit Testing For Games

NUnit | NSubstitute | Fluent Assertions | Humble Object Pattern | Builder Pattern

7 of 25

Unit Testing

Definition:

  • software testing method
  • individual units of source code are tested to determine whether they are work properly.
  • what are being tested?
    • sets of one or more computer program modules together
    • associated control data
    • usage procedures
    • operating procedures

8 of 25

Limitations Of Unit Testing

  • They can only test what you tell them to test. If there’s something that wasn’t accounted for, unit testing cannot test these.�
  • Unit tests can only test if something works, not if something is fun/intuitive/enjoyable. (Playtesting is still important.)�
  • Just because the unit tests pass, still need to test if everything works well together. (This calls for Integration Testing and End-To-End Testing.)

9 of 25

Other Kinds Of Testing

  • NFT (Non-Functional Testing)�
  • Regression Testing�
  • Integration Testing�
  • End-To-End Testing�
  • User Experience Testing�
  • A/B Testing�
  • Playtesting

10 of 25

Unit Testing

11 of 25

Advantages Of Unit Testing

  • Make sure that the code being made works, before adding new code.
    • Easier for finding bugs. �
  • Faster development time / save time.
    • No need to play the game for testing if the code or game logic works.
    • Time of testers can be used for testing for fun, or testing for all the other things that unit tests cannot cover. �
  • Easier to work with other developers.
    • When other developers see what the unit tests are testing for, it’s easier for them to figure out the code, aside from the documentation/comments/etc.

12 of 25

Unit Testing

Where can this be used?

  • Although the format here is teaching with Unity and C#, unit testing is game-engine agnostic and language agnostic, meaning the principles taught here can also be used for Unreal Engine, Godot Engine, etc.

13 of 25

Unit Testing For Godot Engine

14 of 25

Unit Testing - Unity Example

How To Follow Along:

  • download & install Unity (preferably 2019 & later)
  • download & install NSubstitute:
    • version 2.0.3 -- https://www.nuget.org/packages/NSubstitute/2.0.3
    • installation instructions here: https://youtu.be/r7VkbV0PRC8?t=1116
      • Nsubstitute.2.0.3.nupkg > lib > net35 > NSubstitute.dll
  • download & install Fluent Assertions

15 of 25

Unit Testing - Unity Example

What Will Be Covered:

  • NUnit
  • NSubstitute
  • Fluent Assertions
  • Humble Object Pattern
  • Builder Pattern

16 of 25

Unit Testing - Unity Example

Important Things About Unit Tests:

  • Each test must be self-contained (one testcase function/method cannot rely on another testcase function/method).

Important Parts Of A Unit Test:

  • Assign / Arrange
  • Act
  • Assert

17 of 25

Unit Testing - Unity Example

How To Follow Along:

  • (go to Unity Live Coding)

18 of 25

19 of 25

Learning Resources

Jason Weimann

20 of 25

Learning Resources

Infallible Code

21 of 25

Learning Resources

Miscellaneous

22 of 25

Learning Resources

Miscellaneous

23 of 25

Any Questions?

24 of 25

Getting Started In Unit Testing For Games

25 of 25

Getting Started In Unit Testing For Games

twitter.com/ChuaBernice�Slides available at BerniceChua.com