Tavia Young

Ranch Hand
+ Follow
since Mar 15, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Tavia Young

Hi All,

As I slowly begin to grasp the ideas of unit testing, I was wondering what would be the best way to test a database backend (e.g. create/delete/update/edit instances of a Class)? I have looked into dbUnit and am not quite sure how to proceed. How would I establish a connection with the database? Do I need to manage the transactions?

Thanks very much!
20 years ago
The examples are helpful, Lasse. The confusing bit for me still is if the code included a line such as if(param != null), the test fails.

The additional error generated is due to the org.mockejb.ExceptionHandler intercept as I am testing outside the container with mockEJB's. Is there any reason why this error is raised?

Thanks again!
20 years ago
I see your point, Lasse. Thanks again for the explanation. By testing for the specific exception, (e.g. a NullPointerException in the case where a parameter passed to a method results in a null) we are verifying the code does throw this exception. If code were written to include a check (e.g. parameter != null), this would lead to a fail. So, would it be correct to then check for the expected exception thrown when the parameter is not null?

I am testing this within a J2EE environment and I also get an error from the EJB even though the unit tests pass?
20 years ago
Thanks, Lasse. You're so quick! =)

If the testInvalidInput() passes, this would mean that the code does not check for invalid input?! My confusion is that if I alter the code to check for null values, this test would fail.

I hope you could shed more light on this for me. Thanks again!
20 years ago
Thank you, Ilja.

I'm still somewhat confused. Using Lasse's example above, in the case where the test passes, this would mean that the code does not check for invalid input (i.e. the InvalidArgumentException). If the code is changed to check for invalid input, the test fails.
20 years ago
Oops - I misinterpreted the example that Lasse provided above. If division by zero occurs, it should catch the InvalidArgumentException and the test will pass.

But, what happens in the case if the Exception you're looking for is nested?
20 years ago
Right, I see.

In the example below, if division by zero occurs, the test will fail. Is this failure a sign of "success" that the code accounts for null input? Should both tests be written to pass?
20 years ago
With regards to testing for null values that are passed into a method, would the logical step be to write a test to initially catch the NullPointerException (i.e. as Craig mentions above) and then test for the case in which such parameters are not null? How would these two tests be able to co-exist in the TestCase?

Thanks much!
20 years ago
That makes good sense, Lasse.

In reference to the above messages re Interfaces and Easy Mock/JMock, does it make more sense to test the struts FormFile class or the implementation of the class, CommonsFormFile? I always get so confused when it comes to java IO and file uploads!
20 years ago
You guy are fabulous! I agree - there doesn't seem to be much documentation available for JMock.

What are your views on units tests for reading and writing files (i.e. the classes in java.io.*)? Thanks again! =)
20 years ago
Thanks a bunch, Lasse. JMock seems like an interesting tool to use. Will investigate some more...
20 years ago

Originally posted by Jeanne Boyarsky:
You would test the code that uses the interface the same way as "regular" code.



Thanks very much, Jeanne & Ilja.

I realize that I should really be testing the code which makes use of the Interface, as Jeanne mentioned above. For example, if I were to test the Struts FormFile, how would one declare this Interface (i.e. The code I would like to test has some operations performed on a FormFile object.)?

Thanks again!
20 years ago
Thanks very much, Lasse. =)

On an related (or unrelated) note, how would one go about testing a class that is declared as an Interface? Thanks again!
20 years ago
Thanks, Lasse and Junilu. If you could post an example, that would be great. =)
20 years ago
Thanks for your reply, Junilu. I think it makes good sense to test the customized Utility class with a separate TestCase; however, could you elaborate a bit more on "feature envy"?

I'm also curious if there is a case where you would want to test two classes together? If so, how would one go about it?

Thanks again!
20 years ago