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: Solution",
"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: 11d0b7309e383ef498cfc7ff4de9ec1a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Tests_14s
{
internal class ScriptAddingTests
{
private const string k_filePath = "Assets/Tests";
[SerializeField]
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: c2f8119123697e1438a83380ff07eb04
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
{
"name": "Tests_14s",
"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: 40ff9160e91e6984fb327fb94555999c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: