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 7054073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:34:56+00:00 2026-05-28T03:34:56+00:00

How to write test cases for SQl queries? is there any procedure or format

  • 0

How to write test cases for SQl queries?

  • is there any procedure or format to follow.
  • for instance i am having an insert query with complex joins, and how to develop testcase for that.
  • 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-28T03:34:56+00:00Added an answer on May 28, 2026 at 3:34 am

    That seems to be interesting, as I am not sure of your requirement.

    IMHO, test cases are good to be written for functional or system testing (or Black box testing in general). Test cases are a translation of the requirements specs or the User stories. In case of testing a query, I am not sure if we need to write a test case (this becomes white box testing). In such a case it better to write Unit tests for them than creating manual test cases. May be I am missing something here.

    However considering that you have a different opinion which I am not aware of, following is my idea.

    If your User Story or the requirements spec explicitly talks about number and type of joins, tables to be used etc. then you can write test cases separately to check if there are any deviations. Eg. One test case can check for the type joins to check if they are as per the requirements and another test case can verify the tables that are used, to check if the developer has used only the intended tables and nothing else.

    EDIT: In case you are willing to write unit tests, please check out DBUnit which helps you

    1. Create a connection to DB easily from a unit test case
    2. To create sample data in XML and load them to your tables
    3. Verify the data after performing some database transactions or Assert data in a single step

    For example, consider the following scenario. You have a DB of a school. You have now written a complex query which retrieves a list of students. You have to check if this query is working fine. Then you can create a unit test case using DBUnit or Unitils which will dynamically create your table and load your sample data, execute your query and then compare the resultset with the data which you expect. All in a single automated unit test.

    This is an example from Unitils,

    public class UserDAOTest extends UnitilsJUnit4 {

    @Test
    @DataSet("UserDAOTest.testFindByMinimalAge.xml")
    public void testFindByMinimalAge() {
        List<User> result = userDao.findByMinimalAge(18);        
        assertPropertyLenientEquals("firstName", Arrays.asList("jack"), result);
    }
    

    }

    Before this test is executed, the sample data from this "UserDAOTest.testFindByMinimalAge.xml" will be loaded into the table which you configure and later the test and the query inside it will be executed. Similarly if you use the annotation @ExpectedDataSet instead of @DataSet the data in this xml will be used for comparison of the result set after the test is executed.

    In case you are using JPA-Hibernate, you can also do effective unit testing by using an in-memory DB.

    Hope this helps.

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

Sidebar

Related Questions

I have a SQL query: String S = Editor1.Content.ToString(); Response.Write(S); string sql = insert
I need to write test cases for my application. I've chosen NUnit. Please let
I need to write a use cases to test the asp.net mvc applicatoin. How
How to write test in Nunit to test that only one instance is created
I am wondering should I write unit test for everything. There are some classes
I am learning how to write test cases using Rspec. I have a simple
I have to write the following unit test cases in testng: saveProductTest which would
I would like to write application which will iterate trough certain test cases and
I am trying to write a SQL query that pulls from 3 tables and
This question arise while trying to write test cases. Foo is a class within

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.