IntegrationTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using NUnit.Framework;
  2. using UnityEngine.InputSystem;
  3. using UnityEngine.InputSystem.LowLevel;
  4. // Disable irrelevant warning about there not being underscores in method names.
  5. #pragma warning disable CA1707
  6. // These tests are the only ones that we put *in* the package. The rest of our tests live in Assets/Tests and run separately
  7. // from our CI and not through upm-ci. This also means that IntegrationTests is the only thing we put on trunk through our
  8. // verified package.
  9. //
  10. // Rationale:
  11. // (1) Our APIVerificationTests have extra package requirements and thus need a custom package manifest.json. This will not
  12. // work with upm-ci.
  13. // (2) The tests we have in Assets/Tests exercise the input system in isolation. Having these run on trunk in addition to our
  14. // CI in the input system repo adds little value while adding extra execution time to trunk QV runs. This is unlike
  15. // the integration tests here which add value to trunk by making sure the input system is intact all the way through
  16. // to the native input module.
  17. // (3) If we added everything in Assets/Tests to the package, we would add more stuff to user projects that has no value to users.
  18. //
  19. // NOTE: The tests here are necessary to pass the requirement imposed by upm-ci that a package MUST have tests in it.
  20. public class IntegrationTests
  21. {
  22. [Test]
  23. [Category("Integration")]
  24. public void Integration_CanSendAndReceiveEvents()
  25. {
  26. var keyboard = InputSystem.AddDevice<Keyboard>();
  27. try
  28. {
  29. InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
  30. InputSystem.Update();
  31. Assert.That(keyboard.aKey.isPressed, Is.True);
  32. }
  33. finally
  34. {
  35. InputSystem.RemoveDevice(keyboard);
  36. }
  37. }
  38. }