Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZenjectIntegrationTestFixture.Setup destroys objects that prevent UnityTests from running. #267

Open
underscoreglook opened this issue Jun 29, 2022 · 0 comments

Comments

@underscoreglook
Copy link

underscoreglook commented Jun 29, 2022

Repro steps:

This is on Unity 2020.3.8f1

  1. Create a class:
public class BlahBlah : ZenjectIntegrationTestFixture
{
    [UnityTest]
    public IEnumerator RunTest1()
    {
        // Setup initial state by creating game objects from scratch, loading prefabs/scenes, etc

        PreInstall();

        // Call Container.Bind methods

        PostInstall();

        // Add test assertions for expected state
        // Using Container.Resolve or [Inject] fields
        yield break;
    }
}
  1. Run RunTest1 in PlayMode in Unity's test runner. Notice that it hangs.
  2. Put breakpoint on PreInstall() in Rider or whatever IDE you have and attach to Unity. Run test again, notice that breakpoint never gets hit.
  3. Comment out the line GameObject.DestroyImmediate(obj); in ZenjectIntegrationTestFixture.SetUp. Run test again, notice that the breakpoint IS hit this time.

What is expected instead

Expected is that the test runner doesn't hang and the actual test is run (and the breakpoint is hit) even as listed in step 3.

Other notes

It seems that the only object that's destroyed is "Code-based tests runner", which seems to be the thing actually running the tests.

Workaround

I replaced the offending line with

                if (obj.name != UnitTestRunnerGameObjectName)
                {
                    Object.DestroyImmediate(obj);
                }

and my tests work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant