views:

251

answers:

6

I've recently starting learning java web development and I want to learn/understand:

  1. What constitutes good java test good? For example, if there is back-end java code that validates user input from a form and then inserts into a db table, what should the respective test code look like?

  2. How do testing frameworks like TestNG, JUnit, etc. fit into the java code testing process?

Thanks.

+7  A: 

That's a pretty big topic... you might want to pickup or download a copy of "Pragmatic Unit Testing with JUnit" (http://pragprog.com/titles/utj/pragmatic-unit-testing-in-java-with-junit) it covers what you are looking for.

Also, the JUnit (http://junit.org) website should be a good starting point.

Good luck.

cjstehno
Given such a broad question, I'd think the beginner-to-intermediate level approach of these "starter kit" Pragmatic Bookshelf books is just right.
Jonik
Thanks for recommending "Pragmatic Unit Testing with JUnit," it was a good introduction to the topic of unit testing and JUnit itself - and most importantly, it answered the questions in my original post. However, for more depth about testing and JUnit, it seems that "JUnit in Action" is a good option.
Dan
+4  A: 

I dare to say that JUnit is the most popular Java testing framework out nowadays. There are fairly a lot of resources around. To start, there's an book called JUnit in Action which covers servlet (web) testing as well. Then there are lot of online resources to learn how to JUnit-test servlets.

As to the actual testing: best would be to test the complete request-response cycle as well as the individual steps involved in the cycle. This may sound a bit tedious but it also depends on business requirements what use cases exactly you need to test.

BalusC
A: 

If you really want to get started with Java Unit testing for web development you may want to look into the Appfuse/Appfuse 2 projects, they're both Java based and both have stupendous tutorials to get you started.

Appfuse generates a pre-setup project for you so you can see how it fits together and works. Additionally it allows you to pick from some frameworks of your choosing to do web-development with, and integrates those with JUnit.

Although be warned that the projects are a bit old; even so it's a great way to get started learning about unit testing.

leeand00
A: 

I'd start with JUnit. Google some examples of its usage. Keep your methods small.

ECLEmma is then a useful Eclipse plugin for monitoring test coverage.

rich
A: 

The jUnit plugin for eclipse is quite useful, also the metrics package will analyse code coverage, and look at what code has been tested and what needs to be tested. Also analysing the different paths through your program, pretty useful if needing something quick on how 'tested' your code is...

Mark Iliffe
A: 

Junit is more direct and simpel to use if you start to learn Java: TestNG has more features but maybe is more complex.

alepuzio