TestMustExpectAllLogsAttribute.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace UnityEngine.TestTools
  3. {
  4. /// <summary>
  5. /// The presence of this attribute will cause the test runner to require that every single log is expected. By
  6. /// default, the runner will only automatically fail on any error logs, so this adds warnings and infos as well.
  7. /// It is the same as calling `LogAssert.NoUnexpectedReceived()` at the bottom of every affected test.
  8. ///
  9. /// This attribute can be applied to test assemblies (will affect every test in the assembly), fixtures (will
  10. /// affect every test in the fixture), or on individual test methods. It is also automatically inherited from base
  11. /// fixtures.
  12. ///
  13. /// The MustExpect property (on by default) lets you selectively enable or disable the higher level value. For
  14. /// example when migrating an assembly to this more strict checking method, you might attach
  15. /// `[assembly:TestMustExpectAllLogs]` to the assembly itself, but then whitelist failing fixtures and test methods
  16. /// with `[TestMustExpectAllLogs(MustExpect=false)]` until they can be migrated. This also means new tests in that
  17. /// assembly would be required to have the more strict checking.
  18. /// </summary>
  19. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
  20. public class TestMustExpectAllLogsAttribute : Attribute
  21. {
  22. /// <summary>
  23. /// Initializes and returns an instance of TestMustExpectAllLogsAttribute.
  24. /// </summary>
  25. /// <param name="mustExpect">
  26. /// A value indicating whether the test must expect all logs.
  27. /// </param>
  28. public TestMustExpectAllLogsAttribute(bool mustExpect = true)
  29. => MustExpect = mustExpect;
  30. /// <summary>
  31. /// Returns the flag of whether the test must expect all logs.
  32. /// </summary>
  33. public bool MustExpect { get; }
  34. }
  35. }