Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:36:42+00:00 2026-05-23T16:36:42+00:00

I have a small experience with JUnit and TestNG , and today I need

  • 0

I have a small experience with JUnit and TestNG, and today I need to do some Unit Testing for Java database code.

I really don’t know how I can achieve this. because I think it’s more difficult to test databases than normal code.

Is there any clues you can give me ?

Thanks.

EDIT

What do you think about DbUnit

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:36:42+00:00Added an answer on May 23, 2026 at 4:36 pm

    You can get started with DbUnit.

    By the way, you do not test databases when you unit test the classes accessing the database. You ought to be putting the database in a known state before and after your tests, and you ought to verify that your classes have fulfilled their contracts.

    Your following was more specific about DbUnit:

    What do you think about DbUnit

    DbUnit has been around for quite sometime. As far as plain DAO (Data Access Object) implementations are concerned (assuming that you are following the DAO pattern), DbUnit is a good fit, as you can setup the state of the database before testing the DAO, then execute the test against the DAO classes and verify that the expected operation completed successfully. Like other JUnit tests, you can also expect exceptions thrown by the DAO, if the contract of the DAO specifies that exceptions would be thrown, for instance, in cases where data is not found.

    Do keep in mind that there is nothing spectacular about testing against a database. You ought to focus on testing your classes instead of testing the database. In simpler words, a database (and the JDBC driver) ought to be seen as collaborators for your SUT (System-Under-Test) and not as the SUT. It is your DAO classes and their contracts that ought to be tested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I started work on a small Java app. I have some experience with
I don't have much experience with JavaScript. However I wanted to do a small
i have to write small java database application with several tables. With that i
I have some experience with JavaScript - but mainly with some small stuff, I
I have a client that runs a small business. They need a custom database
I have a small amount of experience using SVN on my development projects, and
I have a little experience developing small command-line applications with Python. I want to
I just started using CakePHP for a small project. I have rails experience, and
I have small utility that does some processing on a file and changes the
I have small database of business and their addresses. Using the Google Geocode API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.