Anonymous | Login
Project:
RSS
  
News | My View | View Issues | Roadmap | Summary

View Revisions: Issue #32275 All Revisions ] Back to Issue ]
Summary 0032275: jUnit: add capability to assert on logs
Revision 2016-02-18 14:51 by alostale
Steps To Reproduce Suppose you want to test that some warn message is logged after doing some process. Ideally the test would look like:

  @Test
  public void unbalancedAdminModeShouldLogWarn() {
    setTestLogAppenderLevel(Level.WARN);

    OBContext.setAdminMode(true);
    OBContext.restorePreviousMode();
    OBContext.restorePreviousMode(); // second restore is unbalanced

    assertThat(getTestLogAppender().getMessages(Level.WARN),
        hasItem(containsString("Unbalanced calls to setAdminMode")));
  }

Where 1st line sets the threshold for which messages are going to be tracked and the asset gets messages tracked since that point and checks there is a concrete one.
Revision 2016-02-18 14:50 by alostale
Steps To Reproduce Suppose you want to test that some warn message is logged after doing some process. Ideally the test would look like:

  @Test
  public void unbalancedAdminModeShouldLogWarn() {
    setTestLogAppenderLevel(Level.WARN);
    OBContext.setAdminMode(true);
    OBContext.restorePreviousMode();
    OBContext.restorePreviousMode(); // second restore is unbalanced

    assertThat(getTestLogAppender().getMessages(Level.WARN),
        hasItem(containsString("Unbalanced calls to setAdminMode")));
  }


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker