Skip to content

Instantly share code, notes, and snippets.

@sassembla
Last active December 14, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sassembla/5082797 to your computer and use it in GitHub Desktop.
Save sassembla/5082797 to your computer and use it in GitHub Desktop.
Unity's plugin testkit. Minimum. Run automatically in UnityEditor.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
[InitializeOnLoad]
public class UnityEditorTestKit : MonoBehaviour {
static UnityEditorTestKit () {
testRun();
}
static void Assert(bool condition, string message) {
if (!condition) throw new Exception(message);
}
/**
run tests
*/
static void testRun () {
/*
setUp
*/
Action setUp = () => {
Debug.Log("test setUp");
};
/*
tearDown
*/
Action tearDown = () => {
Debug.Log("test tearDown");
};
Debug.Log("test start");
var testList = new List<Action>();
collectTestsTo(testList);
// check avail:count, type, condition
foreach (var currentTest in testList) {
setUp();
currentTest();
tearDown();
}
Debug.Log("test over");
}
/**
test cases
*/
static void collectTestsTo (List<Action> testList) {
// |
// TEST HERE \|/
testList.Add(
() => {
Debug.Log("the 1st test case");
Assert(true, "yeahh-hooo");
}
);
testList.Add(
() => {
Debug.Log("the 2nd test case");
Assert(false, "should be failure");
}
);
// TEST HERE /|\
// |
}
}
@sassembla
Copy link
Author

updated.
delegateをinvokeするのではなく、Actionに切り替え。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment