Maybe A Silly Question But Should I Click Run All?

The title says it all. So far It’s just okay if I just run selected. But then the problem occurs when I click the run all. It seems like I write it only for individual testing, and not designed to pass the run all tests.
Can someone give me some resources to properly write unit test in unity? Anything will be appreciated.
Thankss!

Are you doing a bunch of setup for your test, and not cleaning up afterwards?

About Unity Test Framework | Test Framework | 1.3.3 (unity3d.com)
Installation | NUnit Docs

Uhh, yes. What kind of cleaning up should I did? I was just basically doing login, select avatar, and then play tests whatever on that scene.

Thanks for the source. But I can’t find the articles that explains how to write proper unit test in unity. You noticed that I did something wrong right when you asked that question?

Like what I mentioned above. I passed any single test, but then it failed when I run all at once. So there must be a proper way to make run all works. Or is it okay to just run the test one by one?

Any setup that you do for your tests will remain in place, unless you specifically tear it down.
That’s why there are both SetUp- & TearDown-Methods for Tests.
https://docs.nunit.org/articles/nunit/writing-tests/setup-teardown/index.html
Most likely the setup of one of your tests is influencing the other tests. Make sure you teardown everything you setup for the test, so you can run clean tests

1 Like

I’ve read that. And yes in UnitySetup I loaded the Initialize scene.

        public static async UniTask SkipToSelectAvatar(bool isGuest = false)
        {
            AsyncOperation operation = SceneManager.LoadSceneAsync("Initializer.unity", LoadSceneMode.Single);

            await UniTask.WaitUntil(() => operation.isDone);

            AppMain.State = EAppState.LOGIN;

            Login(isGuest);

            await UniTask.Yield();

            //var cts = new CancellationTokenSource();
            //cts.Cancel();

            await UniTask.WaitUntil(() => AppMain.State == EAppState.SELECT_AVATAR); //.Timeout(TimeSpan.FromSeconds(20), DelayType.DeltaTime, PlayerLoopTiming.Update, cts);
        }

But the destination wasn’t in Initialize. The tests is in the other scene (let’s say scene3). At the end of the test, what should I clean up? Do I need to unload the scene3? There isn’t much helpful example I found on the internet. Including this

Yes. You’ll probably also want to LogOut(), since you’re doing a login, and reset AppMain.State.

Ahh I see. I was assuming that all values changed when unit testing will be automatically resetted after it has finished.