I have to write a testcase for a method which inserts records in data base.
Can jUnit testcase actually inserts data in database when we use it to test a function which inserts the data in database? After running the testcase can I check the data in database table?
If you write a test for code that performs database inserts, that code will perform inserts when you exercise it.
You can check the data in the database after running the testcase. You can run queries to tell whether the state of the database is correct. Test frameworks will automate this for you.
Testing against a database requires some planning. For one thing you will have to figure out what database you will test against. If you test against a database in your dev environment you may be impacted by data changes and your tests may fail unpredictably. Using an in-memory database like H2 is a popular choice in order to ensure that your tests have a dedicated database in a predictable state.
DBUnit is a test framework that simplifies database testing. You can specify the data that you want the database to be populated with prior to the test, and you can specify what data you expect to be in the database after the test, and the framework will check whether the actual data matches what you expect.