Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

The beginnings of a useful testing framework #1305

Merged
merged 9 commits into from
Mar 5, 2020

Conversation

jamiebrynes7
Copy link
Contributor

@jamiebrynes7 jamiebrynes7 commented Feb 25, 2020

Description

This PR condenses some of the patterns we've used in testing into a MockWorld class which helps you write integration tests in a fluent and easy to understand way. The goal of this was to make it very easy to spin up the full stack with a mock connection and tick through frames. This is visible in the API which looks something like:

MockWorld.Create(new MockWorld.Options())
	.Step(world => /* first frame */)
	.Step(world => /* second frame */)
	...

The MockWorld classes has a minimal feature set, and can be extended in the future:

  • Handling the creation and management of the world & player loop.
  • Create and link GameObjects (with a given component), a future extension could be adding a <T1, T2> & <T1, T2, T3> version.
  • Passing arbitrary context through 'frames' simply by returning an object in the lambda. This context will be passed through any number of frames until it is replaced:
     MockWorld.Create(new MockWorld.Options())
     	.Step(world => 10)
     	.Step((world, number) => /* do something with number */)
     	.Step(world => /* do something without number */)
     	.Step((world, number) => { /* do something with number */ return "foo"; })
     	.Step((world, str) => /* do something with string */);

This is all wrapped up in the MockBase abstract class which test fixtures can inherit from. This has a simple SetUp and TearDown where the World is created and then disposed so each test can have a fresh world to start with.

I've ported the existing tests in the Test Project to this new paradigm, there are tests in Core that would benefit from this API but we may want to move around the location of the Mock* objects in order to use them there.

Commits are ordered!

Tests

Old tests ported & still passing.

Documentation

  • Changelog

@improbable-prow-robot improbable-prow-robot added jira/no-ticket Indicates a PR has no corresponding JIRA ticket do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. A: core Area: Core GDK labels Feb 25, 2020
.Step(world => { world.Connection.CreateEntity(EntityId, BasicEntity()); })
.Step(world =>
{
var (_, readerBehaviour) = world.CreateGameObject<ExhaustiveSingularReaderBehaviour>(EntityId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a little unclear why this test works the way it does. Can we somehow make it clearer that this works because the BasicEntity does not contain the component that the monobehaviour here has a reader for?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not change the tests themselves in this PR

@jamiebrynes7 jamiebrynes7 force-pushed the tests/lil-framework branch 2 times, most recently from a200f81 to 44b240e Compare February 28, 2020 13:19
Copy link
Contributor

@zeroZshadow zeroZshadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, dont forget the changelog

@jamiebrynes7 jamiebrynes7 marked this pull request as ready for review February 28, 2020 14:48
@improbable-prow-robot improbable-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 28, 2020
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@paulbalaji paulbalaji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it

Copy link
Contributor

@jessicafalk jessicafalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like it :D

@jamiebrynes7 jamiebrynes7 force-pushed the tests/lil-framework branch from a4707de to a608556 Compare March 5, 2020 11:38
@jamiebrynes7 jamiebrynes7 merged commit 76f22ce into develop Mar 5, 2020
@jamiebrynes7 jamiebrynes7 deleted the tests/lil-framework branch March 5, 2020 12:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A: core Area: Core GDK jira/no-ticket Indicates a PR has no corresponding JIRA ticket size/XXL Denotes a PR that changes 600+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants