Loading ...
Sorry, an error occurred while loading the content.

Newbie: structuring tests that iterate over test datasets

Expand Messages
  • Ramon Felciano
    Hi -- I m trying JUnit for the first time, and would like to use it to create a suite of unit tests for an LDAP user authentication package. I ve created a
    Message 1 of 1 , Oct 10, 2000
    View Source
    • 0 Attachment
      Hi --

      I'm trying JUnit for the first time, and would like to use it to
      create a suite of unit tests for an LDAP user authentication package.
      I've created a class that has several test methods that test the
      various classes in this authentication package. These work against
      several dummy SmallUser accounts that I create locally to mirror
      known accounts in LDAP. I then iterate through these users in the
      actual test methods:

      public void testAuthenticedUserClass() {
      for (Enumeration e = users.elements(); e.hasMoreElements();){
      SmallUser testuser = (SmallUser)(e.nextElement());
      AuthenticatedUser user;
      try {
      user = new AuthenticatedUser(testuser.uid, testuser.password);
      assertNotNull("Can't create user "+testuser.uid, user);
      } catch (NamingException err) {
      fail("Got NamingException with user "+testuser.uid+");
      }

      try {
      user = new AuthenticatedUser(testuser.uid, null);
      fail("Authenticated user with null password");
      } catch (NamingException err) { } // we expect this
      }
      }

      The problem with this is that as soon as the first test fails, it
      kicks out of the method and the rest of the tests execute. In the
      above example, if the first AssertNotNull fails then the subsequent
      test isn't run (authenticating the same user with a null password)
      nor are any subsequent users run.

      Am I structuring this incorrectly? This seems like a natural design,
      but I couldn't figure out "the JUnit way" to do it from the FAQ or
      docs. Any suggestions?

      Thanks!

      Ramon
    Your message has been successfully submitted and would be delivered to recipients shortly.