This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"displayName": "Exercise 14: Preserve Test State",
"description": "This section will cover how to let variables and information in your tests survive domain reloads using serialization.",
"interactiveImport": true
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5b6d8e9ea10a1c34ca6140ed7884a77c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Tests_14
{
internal class ScriptAddingTests
{
private const string k_filePath = @"Assets\\Tests";
private string fileName;
[UnitySetUp]
public IEnumerator Setup()
{
fileName = Guid.NewGuid() + ".cs";
CreateScript(fileName);
yield return new RecompileScripts();
}
[Test]
public void CreatedScriptIsVerified()
{
var verification = VerifyScript();
Assert.That(verification, Is.EqualTo("OK"));
}
[UnityTearDown]
public IEnumerator Teardown()
{
if (string.IsNullOrEmpty(fileName))
{
Assert.Fail("Could not cleanup file. File name is not available.");
}
var path = Path.Combine(k_filePath, fileName);
if (!File.Exists(path))
{
yield break;
}
File.Delete(path);
yield return new RecompileScripts();
}
private void CreateScript(string fileName)
{
var path = Path.Combine(k_filePath, fileName);
try
{
File.WriteAllText(path, @"
public class MyTempScript {
public string Verify()
{
return ""OK"";
}
}");
}
catch(DirectoryNotFoundException)
{
Assert.Inconclusive("The path to file is incorrect. Please make sure that the path to TempScript is valid.");
}
}
private string VerifyScript()
{
Type type = Type.GetType("MyTempScript", true);
object instance = Activator.CreateInstance(type);
var verifyMethod = type.GetMethod("Verify", BindingFlags.Instance | BindingFlags.Public);
var verifyResult = verifyMethod.Invoke(instance, new object[0]);
return verifyResult as string;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ad565e57cc739c47827deb494a3c5aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
{
"name": "Tests_14",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": true,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": []
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7b4ee5f8eff008e4c857906fefe4e926
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: