TestMustExpectAllLogsAttribute.cs 1.5 KB

12345678910111213141516171819202122232425262728
  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. public TestMustExpectAllLogsAttribute(bool mustExpect = true)
  23. => MustExpect = mustExpect;
  24. public bool MustExpect { get; }
  25. }
  26. }