どのような種類の開発と同様、パッケージにテストを追加することは推奨されます。パッケージにテストを設定するには、以下の 3 点を行う必要があります。
Editor と Runtime サブフォルダー内のパッケージの Tests フォルダーにテストファイルを加えます。例えば、テストを含む単純なパッケージは以下のようになります。
<package-root>
├── package.json
├── Editor
│ ├── <company-name>.<package-name>.Editor.asmdef
│ └── EditorExample.cs
├── Runtime
│ ├── <company-name>.<package-name>.asmdef
│ └── RuntimeExample.cs
└── Tests
├── Editor
│ ├── <company-name>.<package-name>.Editor.Tests.asmdef
│ └── EditorExampleTest.cs
└── Runtime
├── <company-name>.<package-name>.Tests.asmdef
└── RuntimeExampleTest.cs
これらの各サブフォルダーには .asmdef
ファイルが含まれている必要があります。このファイルはエディターとランタイムアセンブリへの参照を提供します。アセンブリ定義ファイルは、テストアセンブリファイルへの参照も提供します。詳細は、テスト用アセンブリ定義ファイル を参照してください。
アセンブリ定義ファイルを直接編集できます。以下の参照を必ず加えてください。
属性 | 型 | 説明 |
---|---|---|
name | 文字列 | ファイル拡張子を除いたアセンブリの名前。 |
references | 文字列の配列 | エディターとランタイムのアセンブリへの参照。アセンブリ定義ファイルは、テストによって異なる参照が必要です。 - エディターテストの場合は、パッケージのエディターアセンブリとランタイムアセンブリへの参照を加えます。 - ランタイムテストの場合は、パッケージのランタイムアセンブリのみへの参照を追加します。 |
optionalUnityReferences | 文字列の配列 | アセンブリをテストアセンブリとマークするには、この Unity 参照のリストに "TestAssemblies" を加える必要があります。これにより、nunit.framework.dll と UnityEngine.TestRunner.dll ライブラリへの参照がアセンブリ定義に追加されます。 |
includePlatforms | 文字列の配列 | エディターテストの場合は、このプラットフォームのリストに "Editor" プラットフォームを加える必要があります。 |
ヒント: Inspector でアセンブリ定義ファイルを編集することもできます。詳細は アセンブリの定義 を参照してください。
以下は、エディターテスト .asmdef
ファイルの例です。
{
"name": "MyCompany.MyPackage.Editor.Tests",
"references": [
"MyPackage.Editor",
"MyPackage"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": []
}
以下は、ランタイムテスト .asmdef
ファイルの例です。
{
"name": "MyCompany.MyPackage.Tests",
"references": [
"MyPackage"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"excludePlatforms": []
}
埋め込みパッケージの場合は開発中のため、明示的にテストを有効にする必要はありません。
ただし、他の種類の依存関係に対しては、testables 属性をプロジェクトマニフェストに加え、実行するテストを含むパッケージの名前を追加する必要があります。これには、プロジェクトの直接的および間接的な依存関係が含まれます。以下はその例です。
{
"dependencies": {
"com.unity.some-package": "1.0.0",
"com.unity.other-package": "2.0.0",
"com.unity.yet-another-package": "3.0.0",
},
"testables": ["com.unity.some-package", "com.unity.other-package"]
}
この例では、com.unity.some-package と com.unity.other-package パッケージのテストを、Unity の Test Framework パッケージに加えます。
ノート: テストフレームワークが testables
属性の変更をすぐに反映するとは限らないので、パッケージを再度インポートする必要があるかもしれません。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.