Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Now, imagine you need an object that requires an LDAP (lightweight directory access protocol) server to construct. Now, you could start an LDAP server, give it some data, run your test and then tear it down, but that's a lot of work and more closely resembles integration testing. However, a faster alternative would be to use jMock to mock up an object that returns the data you need. Mocking up objects is only the tip of the iceberg. You can also set expectations of objects (e.g. this method is only called once), set the order methods should be called in, test multi-threaded code, etc.

Example

...

Problems Encountered

...

  1. I get a java.lang.SecurityException when trying to run my unit test.
    • I saw this exception when I had two different versions of JUnit 4. One came with the Eclipse platform and the other was a plugin from a library, Tupelo, that had its own version of JUnit 4. Both contained a class JUnit4ClassRunner that when both present threw a java.lang.SecurityException. To resolve this issue, I removed the JUnit4 jar file in the Eclipse plugin directory.

Links

...

Links to the libraries used in the above example.

...