pkm
pkm

Reputation: 31

How write JUnit classes to test some java classes which is running in tomcat?

I am using eclipse and using a plugin to trigger JUnit test suite. Now I need to write JUnit test cases which uses highly coupled java classes which can only be run in Tomcat server. How to start so that I can run the JUnit classes to test some java classes which is running in tomcat??

Any help is highly appreciated :)

Upvotes: 3

Views: 218

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48087

First of all: It's hard to write proper tests for highly coupled code. The correct answer is: Introduce indirections to decouple the code from the environment, then test that.

Luckily you write "JUnit-Tests", not "Unit-Tests", because what you're doing is to use JUnit for an integration test (as you're attempting to test several layers together).

Another possibility is to mock the (tomcat-)dependencies. This will enable you to get along without introducing many indirections. Be careful though: If you have too much setup of MockObjects for just a little bit of test and a single assertion at the end, this might not teach you too much about the correctness of your code.

Upvotes: 1

Related Questions