add working example unity package with tests
parent
8e0b824ca9
commit
0555c18f6d
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a62b511ba12825d4d9f992b4ed37a533
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e3a65787d84893340b9dc38af5b7c31f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
[CustomEditor(typeof(TimerComponent))]
|
||||||
|
public class LevelScriptEditor : Editor
|
||||||
|
{
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
TimerComponent myTarget = (TimerComponent)target;
|
||||||
|
|
||||||
|
EditorGUILayout.LabelField("Timer", myTarget.Timer.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f0a715d2f35ea4c40a6f1cdae355c61c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "fake.notarealpackage.Editor",
|
||||||
|
"references": [
|
||||||
|
"fake.notarealpackage.Runtime"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8223b1b52474b674a87c6113b6384f10
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e472ec5749e60ca4db87f10cec905d2c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 21861106477d38342a589fc525c4e0bb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6c6729c46a2a6594da2ce1182420ab81
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class BasicCounter
|
||||||
|
{
|
||||||
|
public const int MaxCount = 10;
|
||||||
|
|
||||||
|
public BasicCounter(int count = 0)
|
||||||
|
{
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Increment()
|
||||||
|
{
|
||||||
|
Count = Math.Min(MaxCount, Count + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count { get; private set; }
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0bd8dfbd5c7fc9e439246091668234b0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class SampleComponent : MonoBehaviour
|
||||||
|
{
|
||||||
|
public BasicCounter Counter;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Counter = new BasicCounter(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
Counter.Increment();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 121f2ede62657a84082c012941df22d5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TimerComponent : MonoBehaviour
|
||||||
|
{
|
||||||
|
public BasicCounter Counter = new BasicCounter();
|
||||||
|
public float Timer = 1f;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
Timer -= Time.deltaTime;
|
||||||
|
|
||||||
|
if (Timer > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Counter.Increment();
|
||||||
|
Timer = 1f;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 563e4fb514abf6141b80ca1b71c08889
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"name": "fake.notarealpackage.Runtime"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b20629d7e725e1e449076020f132df2a
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d0f3a0ff2938264498234e4aaa66cf5f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7644cfe4cdc2d0f4ebc7ab351323a576
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,38 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class SampleEditModeTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestIncrement()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var counter = new BasicCounter(0);
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(1, counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMaxCount()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var counter = new BasicCounter(BasicCounter.MaxCount);
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(BasicCounter.MaxCount, counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 88de94cc1489d83488ce54f71b512989
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "fake.notarealpackage.EditorTests",
|
||||||
|
"references": [
|
||||||
|
"fake.notarealpackage.Runtime",
|
||||||
|
"fake.notarealpackage.Editor"
|
||||||
|
],
|
||||||
|
"optionalUnityReferences": [
|
||||||
|
"TestAssemblies"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": []
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b5712d2009ce3b34a8ca077667b16764
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b4f774583b1374a4abe450c7100726bd
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System.Collections;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class SampleComponentTest
|
||||||
|
{
|
||||||
|
private GameObject target;
|
||||||
|
private SampleComponent component;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
target = GameObject.Instantiate(new GameObject());
|
||||||
|
component = target.AddComponent<SampleComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestIncrementOnUpdateAfterNextFrame()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b551b84934711564eb78aab8c16425ac
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,42 @@
|
||||||
|
using System.Collections;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class SamplePlayModeTest
|
||||||
|
{
|
||||||
|
// A Test behaves as an ordinary method
|
||||||
|
[Test]
|
||||||
|
public void NewTestScriptSimplePasses()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var counter = new BasicCounter(0);
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(1, counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
||||||
|
// `yield return null;` to skip a frame.
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator NewTestScriptWithEnumeratorPasses()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var counter = new BasicCounter(3);
|
||||||
|
|
||||||
|
// Use the Assert class to test conditions.
|
||||||
|
// Use yield to skip a frame.
|
||||||
|
yield return null;
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(4, counter.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4dbe2d2dc79550c4d81602bcf94a9824
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,66 @@
|
||||||
|
using System.Collections;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class TimerComponentTest
|
||||||
|
{
|
||||||
|
private GameObject target;
|
||||||
|
private TimerComponent component;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
target = GameObject.Instantiate(new GameObject());
|
||||||
|
component = target.AddComponent<TimerComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestIncrementAfterSomeTime()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 2, component.Counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestTimeScaleIsAffectingIncrement()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
Time.timeScale = .5f;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return WaitForRealSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return WaitForRealSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipping time ignoring Time.scale
|
||||||
|
// https://answers.unity.com/questions/301868/yield-waitforseconds-outside-of-timescale.html
|
||||||
|
public static IEnumerator WaitForRealSeconds(float time)
|
||||||
|
{
|
||||||
|
float start = Time.realtimeSinceStartup;
|
||||||
|
while (Time.realtimeSinceStartup < start + time)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 010121a56a70d60428dc89307eb77b54
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "fake.notarealpackage.RuntimeTests",
|
||||||
|
"references": [
|
||||||
|
"fake.notarealpackage.Runtime"
|
||||||
|
],
|
||||||
|
"optionalUnityReferences": [
|
||||||
|
"TestAssemblies"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": []
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 902aaaf7a59149243b2f4e38fc9f388e
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "com.fake.notarealpackage",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"displayName": "Fake package",
|
||||||
|
"description": "Not a real package",
|
||||||
|
"unity": "2019.2",
|
||||||
|
"unityRelease": "11f1",
|
||||||
|
"keywords": [
|
||||||
|
"nothing"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "Not Real",
|
||||||
|
"email": "notreal@notarealemailendpoint.com",
|
||||||
|
"url": "https://github.com"
|
||||||
|
},
|
||||||
|
"type": "tool",
|
||||||
|
"hideInEditor": false
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4232dbd3889ab6a4393e846291288fb0
|
||||||
|
PackageManifestImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"name": "com.example.packageName",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"displayName": "Example Unity Package",
|
|
||||||
"description": "A package made to test unity-test-runner",
|
|
||||||
"unity": "2019.2",
|
|
||||||
"unityRelease": "11f1",
|
|
||||||
"author": {
|
|
||||||
"name": "Aaron Trudeau",
|
|
||||||
"email": "trudeaua@mail.gvsu.edu",
|
|
||||||
"url": "https://github.com/trudeaua21"
|
|
||||||
},
|
|
||||||
"type": "tool"
|
|
||||||
}
|
|
Loading…
Reference in New Issue