esapi-java-legacy
esapi-java-legacy copied to clipboard
Unit tests should test interface and only interface
From [email protected] on July 31, 2009 15:46:21
The unit tests packaged with ESAPI should only test the interface and not contain code that is specific to the default implementations. This means two things in particular:
- All types should be from the API interfaces
- Methods called on instances being tested should only reflect those in the API
Specific tests that call methods not in the API:
- AuthenticatorTest.testSaveUsers
... more to come.
Original issue: http://code.google.com/p/owasp-esapi-java/issues/detail?id=25
From [email protected] on September 09, 2009 23:54:21
Maybe split the tests in two. One folder for interface and one for default implementations. That way you can still test the default implementations on a finer granularity.
From [email protected] on October 31, 2010 22:57:37
Status: Accepted
Owner: [email protected]
Labels: Milestone-Release2.1
Previous comment had blocked on Google Code issue 186. That is now issue #196.
The original Google Code issue seems to imply that the reference implementation classes should not be tested at all, which is of course absurd. One cannot write meaningful unit tests in the absence of any implementation at all.
That said, if the objection is against testing implementation specific methods in a JUnit test meant to test interfaces, that I can agree with. As noted, the AuthenticatorTest class, which presumably is meant for testing the implementation of only the methods defined in the Authenticator interface, also includes a 'testSaveUsers()' test case that tests the implementation of FileBasedAuthenticator.saveUsers() method, a method which is not defined in the Authenticator interface. Clearly that 'testSaveUsers()' method should be moved to a implementation specific class, such as FileBasedAuthenticatorTests (which does not currently exist).
At this point, I do not think it is prudent to make these changes before the anticipated ESAPI 3.0 release, and for that reason, I have changed this to the 3.0 milestone.