As with any kind of development, it’s good practice to add tests to your package. There are three things you must do to set up tests on your package:
Editor 및 Runtime 하위 폴더에 있는 패키지의 Tests 폴더에 테스트 파일을 추가할 수 있습니다. 예를 들어 테스트가 포함된 단순한 패키지는 다음과 같은 모습일 수 있습니다.
MyPackage
├── package.json
├── Editor
│ ├── MyPackage.Editor.asmdef
│ └── EditorExample.cs
├── Runtime
│ ├── MyPackage.Runtime.asmdef
│ └── RuntimeExample.cs
└── Tests
├── Editor
│ ├── MyPackage.EditorTests.asmdef
│ └── EditorExampleTest.cs
└── Runtime
├── MyPackage.RuntimeTests.asmdef
└── RuntimeExampleTest.cs
각 하위 폴더에는 Editor 및 Runtime 어셈블리에 레퍼런스를 제공하는 .asmdef
파일이 들어 있어야 합니다. 또한 어셈블리 정의 파일은 테스트 어셈블리 파일에 대한 레퍼런스를 제공합니다. 자세한 내용은 테스트용 어셈블리 정의 파일을 참조하십시오.
어셈블리 정의 파일을 직접 편집할 수 있습니다. 다음의 레퍼런스를 추가해야 합니다.
속성 | 타입 | 설명 |
---|---|---|
name | String | 파일 확장자가 없는 어셈블리 이름입니다. |
references | 문자열 배열 | References to the Editor and Runtime assemblies. Assembly definition files require different references, depending on the test type: - For Editor tests, add a reference to the package’s Editor and Runtime assemblies. - For Runtime tests, add a reference to the package’s Runtime assembly only. |
optionalUnityReferences | 문자열 배열 | This list of Unity references must include "TestAssemblies" to mark the assembly as a test assembly. This adds references to the nunit.framework.dll and UnityEngine.TestRunner.dll libraries to the Assembly Definition. |
includePlatforms | 문자열 배열 | For the Editor test, this list of platforms must include the "Editor" platform. |
팁: 인스펙터에서 어셈블리 정의 파일도 편집할 수 있습니다. 자세한 내용은 어셈블리 정의를 참조하십시오.
에디터 테스트 .asmdef
파일은 다음과 같은 모습입니다.
{
"name": "MyPackage.Editor.Tests",
"references": [
"MyPackage.Editor",
"MyPackage"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": []
}
런타임 테스트 .asmdef
파일은 다음과 같은 모습입니다.
{
"name": "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"]
}
This example adds tests for the com.unity.some-package and com.unity.other-package packages in Unity’s Test Framework package.
Note: You might need to import the package again, because the test framework doesn’t always immediately pick up changes to the testables
attribute.