Let's say we have an application that connects to the DB and insert few records. If I want to Unit Test it using Junit, then we will have to connect to the DB and then insert few records and then verify them ? Is this the correct approach. How does it work, as I want to run my unit test cases multiple times. But if I insert same records every time, there will be a unique constraint violation at DB side. How do we handle it. What is the standard practice.
Another question I have is how to unit test web applications that are deployed on containers like tomcat. Should the application be deployed on tomcat and running while unit testing its classes.
Make sure you're testing what you actually want to be testing--here it sounds like you're testing the database connector, which has probably already been tested.
If you're testing your service methods, it may be enough to make sure they're getting called with the appropriate parameters, or that the underlying connector is being called with the appropriate parameters.
You could also use an in-process database for testing purposes so that it starts off with a "clean slate" every test run.