Class TestFramework

java.lang.Object
com.renomad.minum.testing.TestFramework

public final class TestFramework extends Object
These are utility functions for basic automated testing. It turns out you don't really need fancy tools to do excellent testing. Just a committment to quality. Don't let anyone tell you differently.
  • Method Details

    • assertThrows

      public static <T> T assertThrows(Class<T> myEx, ThrowingRunnable r)
      assert that a particular chunk of code throws a particular exception.

      Example usage:

           
               assertThrows(TemplateRenderException.class, "Missing a value for key {missing_key}", () -> tp.renderTemplate(myMap));
           
       
    • assertThrows

      public static <T> T assertThrows(Class<T> myEx, String expectedMsg, ThrowingRunnable r)
    • assertEquals

      public static <T> void assertEquals(T left, T right)
      A helper for testing - assert two generics are equal. If you need to compare two byte arrays, see assertEqualByteArray(byte[], byte[])
    • assertEqualByteArray

      public static void assertEqualByteArray(byte[] left, byte[] right)
      Compares two byte arrays for equality
    • assertEqualByteArray

      public static void assertEqualByteArray(byte[] left, byte[] right, String failureMessage)
    • assertEqualsDisregardOrder

      public static void assertEqualsDisregardOrder(List<? extends CharSequence> left, List<? extends CharSequence> right)
      asserts two lists are equal, ignoring the order. For example, (a, b) is equal to (b, a)

      Note that the lists must be of comparable objects, or else a ClassCastException will be thrown

    • assertEqualsDisregardOrder

      public static void assertEqualsDisregardOrder(List<? extends CharSequence> left, List<? extends CharSequence> right, String failureMessage)
    • assertEquals

      public static <T> void assertEquals(List<T> left, List<T> right)
      asserts that two lists are equal in value and order.

      For example, (a, b) is equal to (a, b) Does not expect null as an input value. Two empty lists are considered equal.
    • assertEquals

      public static <T> void assertEquals(List<T> left, List<T> right, String failureMessage)
      asserts that two lists are equal in value and order.

      For example, (a, b) is equal to (a, b) Does not expect null as an input value. Two empty lists are considered equal.

      Parameters:
      failureMessage - a failureMessage that should be shown if this assertion fails
    • assertTrue

      public static void assertTrue(boolean value)
    • assertTrue

      public static void assertTrue(boolean value, String failureMessage)
      Assert that something is true, and show a message if it fails. This is also handy for including a kind of documentation in your test code. So, please carefully note this example of its use, because there's a certain subtlety at play:

            assertTrue(foo == true, "foo must be true");
           

      Notice something here: The message is a statement about what *should* be true. Sometimes, I see people who do it wrong here - they add a message like *foo was wrong*, but that's a disconcerting thing to see in a test. Do it like the example above, instead.

      One other detail to mention: If this test fails, it doesn't really give you much help about what the value should have been, it merely insists it be true. In some cases, like where you are asserting that a string contains a substring, it is handy to include what you were looking for and what the string was as part of the failure message.

    • assertFalse

      public static void assertFalse(boolean value)
    • assertFalse

      public static void assertFalse(boolean value, String failureMessage)
    • buildTestingContext

      public static Context buildTestingContext(String loggerName)
    • buildTestingContext

      public static Context buildTestingContext(String loggerName, Properties properties)
      This builds a context very similarly to FullSystem.buildContext(), except that it uses TestLogger instead of Logger
      Parameters:
      loggerName - this will assign a human-readable name to the logger's LoggingActionQueue so we can distinguish it when reviewing the threads
      properties - If you want, you can inject a properties object here, to have greater control over your test. Using a parameter of null here will cause the system to obtain properties from the minum.config file
    • shutdownTestingContext

      public static void shutdownTestingContext(Context context)