UnityTestAssemblyBuilder.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Reflection;
  4. using NUnit;
  5. using NUnit.Framework.Api;
  6. using NUnit.Framework.Interfaces;
  7. using NUnit.Framework.Internal;
  8. namespace UnityEngine.TestTools.NUnitExtensions
  9. {
  10. internal class UnityTestAssemblyBuilder : DefaultTestAssemblyBuilder, IAsyncTestAssemblyBuilder
  11. {
  12. private readonly string m_ProductName;
  13. public UnityTestAssemblyBuilder()
  14. {
  15. m_ProductName = Application.productName;
  16. }
  17. public ITest Build(Assembly[] assemblies, TestPlatform[] testPlatforms, IDictionary<string, object> options)
  18. {
  19. var test = BuildAsync(assemblies, testPlatforms, options);
  20. while (test.MoveNext())
  21. {
  22. }
  23. return test.Current;
  24. }
  25. public IEnumerator<ITest> BuildAsync(Assembly[] assemblies, TestPlatform[] testPlatforms, IDictionary<string, object> options)
  26. {
  27. var productName = string.Join("_", m_ProductName.Split(Path.GetInvalidFileNameChars()));
  28. var suite = new TestSuite(productName);
  29. for (var index = 0; index < assemblies.Length; index++)
  30. {
  31. var assembly = assemblies[index];
  32. var platform = testPlatforms[index];
  33. var assemblySuite = Build(assembly, options) as TestSuite;
  34. if (assemblySuite != null && assemblySuite.HasChildren)
  35. {
  36. assemblySuite.Properties.Set("platform", platform);
  37. suite.Add(assemblySuite);
  38. }
  39. yield return null;
  40. }
  41. yield return suite;
  42. }
  43. public static Dictionary<string, object> GetNUnitTestBuilderSettings(TestPlatform testPlatform)
  44. {
  45. var emptySettings = new Dictionary<string, object>();
  46. emptySettings.Add(FrameworkPackageSettings.TestParameters, "platform=" + testPlatform);
  47. return emptySettings;
  48. }
  49. }
  50. }