UtpMessageReporter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEditor.Compilation;
  4. using UnityEditor.TestTools.TestRunner.Api;
  5. namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
  6. {
  7. internal class UtpMessageReporter : IUtpMessageReporter
  8. {
  9. public ITestRunnerApiMapper TestRunnerApiMapper;
  10. public IUtpLogger Logger;
  11. public UtpMessageReporter(IUtpLogger utpLogger)
  12. {
  13. TestRunnerApiMapper = new TestRunnerApiMapper();
  14. Logger = utpLogger;
  15. }
  16. public void ReportAssemblyCompilationErrors(string assembly, IEnumerable<CompilerMessage> errorCompilerMessages)
  17. {
  18. var compilationErrorMessage = new AssemblyCompilationErrorsMessage
  19. {
  20. assembly = assembly,
  21. errors = errorCompilerMessages.Select(x => x.message).ToArray()
  22. };
  23. Logger.Log(compilationErrorMessage);
  24. }
  25. public void ReportTestRunStarted(ITestAdaptor testsToRun)
  26. {
  27. var msg = TestRunnerApiMapper.MapTestToTestPlanMessage(testsToRun);
  28. Logger.Log(msg);
  29. }
  30. public void ReportTestStarted(ITestAdaptor test)
  31. {
  32. if (test.IsSuite)
  33. return;
  34. var msg = TestRunnerApiMapper.MapTestToTestStartedMessage(test);
  35. Logger.Log(msg);
  36. }
  37. public void ReportTestFinished(ITestResultAdaptor result)
  38. {
  39. if (result.Test.IsSuite)
  40. return;
  41. var msg = TestRunnerApiMapper.TestResultToTestFinishedMessage(result);
  42. Logger.Log(msg);
  43. }
  44. }
  45. }