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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:49:44+00:00 2026-06-01T04:49:44+00:00

In following code the issue is, that I cannot test dao.add() without using dao.list().size()

  • 0

In following code the issue is, that I cannot test dao.add() without using dao.list().size() and vice versa.

Is this approach normal or incorrect? If incorrect, how can it be improved?

public class ItemDaoTest {

    // dao to test
    @Autowired private ItemDao dao;

    @Test 
    public void testAdd() {
        // issue -> testing ADD but using LIST

        int oldSize = dao.list().size();
        dao.add(new Item("stuff"));
        assertTrue (oldSize < dao.list().size());
    }

    @Test
    public void testFind() {
        // issue -> testing FIND but using ADD

        Item item = new Item("stuff")
        dao.add(item);
        assertEquals(item, dao.find(item.getId()));
    }
}
  • 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-06-01T04:49:46+00:00Added an answer on June 1, 2026 at 4:49 am

    I think your test are valid integration tests as stated above, but I would use Add to aid in the testing of of Find and vice verse..
    At some level you have to allow yourself to place trust in your lowest level of integration to your external dependency. I realize there is a dependency to other methods in your tests, but I find that Add and Find methods are “low level” methods that are very easy to verify.
    They essentially test each other as they are basically inverse methods.

    Add can easily build preconditions for find

    Find can verify that an add was successful.

    I can’t think of a scenario where a failure in either wouldn’t be caught by your test

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

Sidebar

Related Questions

I believe I am having a memory issue using numpy arrays. The following code
I incurred in a compiler dependent issue with the following code (stored in crtp.cc):
I'm having an issue with rails involving javascript. Basically, I have the following code:
Recently I've spotted a very disturbing issue. I've got the following python code: for
I have got the following issue, my function appends code to a string $string
When I turn on Code Coverage in my test settings, on a project that
I'm trying to build this legitimate C++ code in HP-UX 11.11, using HP C/aC++
I am trying to create a file inside a directory using the following code:
I am having the following issue, which I cannot seem to resolve, even searching
I am having an issue with line-height that I cannot quite get my head

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.