Nodachisoft Nodachisoft logo, Katana Sword Icon
  
@Amaji✎ Update January -11-2022

Describes how to deal with Unity Test Runner not recognizing multiple Tests folders in Unity.

Describes how to deal with Unity Test Runner not recognizing multiple Tests folders in Unity.

Abstract

In Unity 2020.3 LTS version, this article describes how to deal with the problem that Unity Test Runner does not recognize your test code when you create it in multiple Tests folders.

When I created test code in the following folder structure, Unity Test Runner only recognized the code under one test folder

Directories And Files

I have created the necessary test code under two Tests folders, as shown above, but However, only one of the Tests folders is recognized.

When I open Unity Test Runner with Window -> General -> Test Runner, it only recognizes Tests under NodachiFrameowork, as shown below.

UTF

What to check

Unity Test Runner has two test modes, Edit Mode and Play Mode. Under the two Tests folders, the test code in Edit Mode is stored respectively.

The Tests folder contains the assembly definition files(xxxx.asmdef) that are required when running the tests, and there is a possibility that the settings are wrong.

In the Unity Editor, click on the assembly definition file(xxxx.asmdef) and check the Inspector on the screen.

Compare the assembly definition file under the Tests folder, which is recognized properly, with the assembly definition file under the Tests folder, which is not recognized properly.

platform

The difference was subtle.

On the left of the image is the assembly definition file that was automatically created under the Tests folder that I created by first pressing the Create EditMode Test Assembly Folder button on the Unity Test Runner.

The right image shows the assembly definition file created by Right-Click -> Craete -> Testing -> Tests Assembly Folder on the Project window of the Unity Editor with the Edit Mode checked.

Differences

If you look carefully, you can already see that The assembly definition files that are not recognized as Tests have a different genre name than Exclude Platforms.

platform

So, the setting was to exclude Edit Mode.

Fix

The assembly definition file is in text format, so it can be opened and edited directly in an editor.

The following is before editing. The highlighted parts have been modified.

Ng_TestsAssembly.asmdef
{
    "name": "XxxxTests",
    "rootNamespace": "",
    "references": [
        "UnityEngine.TestRunner",
        "UnityEditor.TestRunner",
        "Packages needed for testing"
    ],
    "includePlatforms": [],
    "excludePlatforms": [
        "Editor"
    ],
    "allowUnsafeCode": false,
    "overrideReferences": true,
    "precompiledReferences": [
        "nunit.framework.dll"
    ],
    "autoReferenced": false,
    "defineConstraints": [
        "UNITY_INCLUDE_TESTS"
    ],
    "versionDefines": [],
    "noEngineReferences": false
}

以下は修正後です。

OK_TestsAssembly.asmdef
{
    "name": "XxxxTests",
    "rootNamespace": "",
    "references": [
        "UnityEngine.TestRunner",
        "UnityEditor.TestRunner",
        "Packages needed for testing"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": true,
    "precompiledReferences": [
        "nunit.framework.dll"
    ],
    "autoReferenced": false,
    "defineConstraints": [
        "UNITY_INCLUDE_TESTS"
    ],
    "versionDefines": [],
    "noEngineReferences": false
}

After modifying the assembly definition file, I checked Unity Test Runner and found that The test code under the modified folder is now recognized without a hitch.

utf_ok.png

Websites and references that were very helpful.

Page History

date modification
none
 
 
Message sent

Thank you for your message.

Something error has occured!

Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.

Twitter:@NodachiSoft_eng
Name:
 
Replay To:
 
Message:
 
Back
Check the content!

Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".

Name:
 
Reply To:
 
Message:
 
Enter a confirmation key to make sure that you are not operating from a Robot.
Confirmation Key is 95
Back
 / 
Go to Confirmation
Entry fields
Go to Confirmation

There are 5 articles that may be relevant!

System.Type.GetType returns null in Unity C# code

System.Type.GetType returns null in Unity C# code

#Unity#.net✎ 2022-1-11
System.Type.GetType returns null in Unity C# code
Table Of Contents
Describes how to deal with Unity Test Runner not recognizing multiple Tests folders in Unity.
Describes how to deal with Unity Test Runner not recognizing multiple Tests folders in Unity.
Abstract
Abstract
What to check
What to check
Differences
Differences
Fix
Fix
Websites and references that were very helpful.
Websites and references that were very helpful.
Page History
Page History
Nodachisoft © 2021