Terasology / ModuleTestingEnvironment

3 stars 15 forks source link

fix: more consistent disposal of resources at the end of the test #64

Closed keturn closed 3 years ago

keturn commented 3 years ago

A few things here:

We were putting ModuleTestingHelper instances in to this map and never taking them out: https://github.com/Terasology/ModuleTestingEnvironment/blob/38100cf07da848e13103e0b599cb69b881f5a12b/src/main/java/org/terasology/moduletestingenvironment/MTEExtension.java#L54

There were scenarios where we'd be trying to use old instances after their tearDown. And awkward situations like this where it wouldn't consistently be ready before postProcessTestInstance: https://github.com/Terasology/ModuleTestingEnvironment/blob/38100cf07da848e13103e0b599cb69b881f5a12b/src/main/java/org/terasology/moduletestingenvironment/IsolatedMTEExtension.java#L38-L41

This PR addresses these problems with managing the lifecycle of the ModuleTestingHelper instance by using the store mechanism on jupiter's ExtensionContext. See JUnit 5 User Guide: Keeping State in Extensions.

Required to fix tests in https://github.com/Terasology/DynamicCities/pull/94
and likely useful for Pathfinding tests as well.

To Do

keturn commented 3 years ago

Oh, and the name "Cleaner" is a bit less accurate now that I decided that's a good place to throw some additional code that serves as an adapter between MTEExtension and a Helper instance.

I wouldn't spend too long on naming that one; I expect the methods I stuffed in there will change quite a bit after https://github.com/Terasology/DynamicCities/pull/94 drops the last reference to the old class and we can easily split it up.

keturn commented 3 years ago

MTE tests: MTE