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

  • Home
  • SEARCH
  • 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 880549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:07:00+00:00 2026-05-15T12:07:00+00:00

I just discovered when creating some CRUD tests that you can’t set data in

  • 0

I just discovered when creating some CRUD tests that you can’t set data in one test and have it read in another test (data is set back to its initialization between each test).

All I’m trying to do is (C)reate an object with one test, and (R)ead it with the next. Does JUnit have a way to do this, or is it ideologically coded such that tests are not allowed to depend on each other?

  • 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-15T12:07:01+00:00Added an answer on May 15, 2026 at 12:07 pm

    Well, for unit tests your aim should be to test the smallest isolated piece of code, usually method by method.
    So testCreate() is a test case and testRead() is another. However, there is nothing that stops you from creating a testCreateAndRead() to test the two functions together. But then if the test fails, which code unit does the test fail at? You don’t know. Those kind of tests are more like integration test, which should be treated differently.

    If you really want to do it, you can create a static class variable to store the object created by testCreate(), then use it in testRead().

    As I have no idea what version of Junit you talking about, I just pick up the ancient one Junit 3.8:

    Utterly ugly but works:

    public class Test extends TestCase{
    
        static String stuff;
    
        public void testCreate(){
            stuff = "abc";
        }
    
        public void testRead(){
            assertEquals(stuff, "abc");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just discovered the nifty unhandled exception handler for cocoa-touch. Now that I
I have just discovered that if generating assemblies via Reflection.Emit, the .NET framework keeps
I just discovered, quite by accident, that this seems to work: Public Interface Ix
To my amazement I just discovered that the C99 stdint.h is missing from MS
I've just discovered that Oracle lets you do the following: SELECT foo.a, (SELECT c
I've inherited a web app that I've just discovered stores over 300,000 usernames/passwords in
I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as
Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like
I'm just getting dirty in WinForms, and I've discovered, through a lovely tutorial, the
I just pasted some generated javadoc into an eclipse project, to discover none of

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.