//- The Timeout attribute uses Time.timeScale. [UnityTest, Timeout(100000)] public IEnumerator HealthManager() { //- Our health component will take 1,000 seconds to go from zero to full. Let's speed things up by 10x Time.timeScale = 10; try { //- We don't need a specific scene, just load the custom assets AssetDb.Load <HealthManagerTranscript>("HealthManager.asset"); var health = AssetDb.Load <Float>("Health.asset"); //- Set to 0 since once a custom asset is loaded in the editor it stays loaded health.Set(0); //- It looks like forever, but the Timeout attribute will cause a test failure after 10 seconds while (true) { //- This causes a 1/10th of a second delay due to the modified scale yield return(new WaitForSeconds(1.0f)); //- Leaving once the test passes is a successful result. This should take 1 second at the current time scale. if (health >= 0.01f) { yield break; } } } finally { //- reset the time scale so other tests aren't effected. Time.timeScale = 1; } }
public override void Create() { if (LogEntries.HasErrors()) { throw new Exception("Please fix compile errors first"); } var files = AssetDb.FindByLabel("BuildNewService"); using (var assets = AssetEditor.Instance) { var assetNames = new List <string>(); foreach (string filePath in files) { var dir = Path.GetDirectoryName(filePath); var assetName = Path.GetFileNameWithoutExtension(filePath); var scriptPath = $"{dir}/{assetName}.cs"; var monoScript = AssetDb.Load <MonoScript>(scriptPath); var assetPath = $"{dir}/{assetName}.asset"; if (!File.Exists(assetPath)) { Debug.Log($"Building {assetPath}"); assetNames.Add(assetName); var match = namespaceRegex.Match(monoScript.text); var nameSpace = match.Success ? match.Groups[1].Value : ""; assets.Add(assetName, nameSpace, assetPath); } AssetDatabase.ClearLabels(monoScript); } Environment mockEnvironment = AssetDatabase.LoadAssetAtPath <Environment>("Assets/Askowl/Decoupler/Scripts/Environments/Mock.asset"); foreach (var assetName in assetNames) { var assetPath = assets.AssetPath(assetName); var path = Path.GetDirectoryName(assetPath); var nameBase = Path.GetFileNameWithoutExtension(path); switch (assets.Asset(assetName)) { case IServicesManager _: assets .SetFieldToAssetEditorEntry(assetName, "context", $"{nameBase}Context") .InsertIntoArrayField(assetName, "services", $"{nameBase}ServiceForMock"); break; case IContext _: assets.SetField(assetName, "environment", mockEnvironment); break; case IServiceAdapter _: // var contextName = $"{nameBase}Context"; // if (!assets.Exists(contextName)) assets.Load(contextName, Namespace(assetPath), path); // assets.SetFieldToAssetEditorEntry(assetName, "context", $"{nameBase}Context"); break; } } } }
public static Fiber Go(string definitionAsset, string featureFile, string label = "") { var definitions = AssetDb.Load <Definitions>($"{definitionAsset}.asset"); Assert.IsNotNull(definitions, $"Gherkin definitions asset '{definitionAsset}' not found"); var fiber = Fiber.Instance() .WaitFor(_ => definitions.Run(featureFile, label)) .Do(_ => Assert.IsTrue(definitions.Success, definitions.errorMessage)) .Log("<color=grey>Scenario Processing Complete</color>"); fiber.Context(definitions); return(fiber); }
public static void Add <T>(string name) where T : Manager => Add(name, AssetDb.Load <T>(name));