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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:57:11+00:00 2026-05-30T17:57:11+00:00

I have a test case where I add an entity, update it and delete

  • 0

I have a test case where I add an entity, update it and delete the same. Hence, the order of execution is important here. I want it to be :

  1. Create
  2. Update
  3. Delete

Strangely, for just one test case ( out of 15) , JUnit executes it in the following order :

  1. Delete
  2. Update
  3. Create .

How do I tell JUnit to execute them in a specific order ? In other cases, JUnit works totally fine ( executing serially ) . And why does JUnit behave weirdly in this one case ?

Relevant code snippet below :

    private static Date date;
    private static int entity;
    static Parking p;
    public ParkingTests(String name) {
       super(name);
    }
    public void testAdd() throws Exception {
           //Add code here
    }
    public void testUpdate() throws Exception {
            //update code here
    }
    public void testDelete() throws Exception {
            //delete code here
    }
  }

It gets weirder. I run a lot of test cases as part of a suite. If I run just the Parking case, the order is maintained. If I run it along with others, it is sometimes maintained, sometimes not !

  • 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-30T17:57:12+00:00Added an answer on May 30, 2026 at 5:57 pm

    Your kind of situation is awkward, as it feels bad to keep duplicating work in order to isolate the tests (see below) – but note that most of the duplication can be pulled out into setUp and tearDown (@Before, @After) methods, so you don’t need much extra code. Provided that the tests are not running so slowly that you stop running them often, it’s better to waste a bit of CPU in the name of clean testing.

    public void testAdd() throws Exception {
          // wipe database
          // add something
          // assert that it was added
    }
    public void testUpdate() throws Exception {
          // wipe database
          // add something
          // update it
          // assert that it was updated
    }
    public void testDelete() throws Exception {
          // wipe database
          // add something
          // delete it
          // assert that it was deleted
    }
    

    The alternative is to stick everything into one test with multiple asserts, but this is harder to understand and maintain, and gives a bit less information when a test fails:

    public void testCRUD() throws Exception {
          // wipe database
          // add something
          // assert that it was added
          // update it
          // assert that it was updated
          // delete it 
          // assert that it was deleted
    }
    

    Testing with databases or collections or storage of any kind is tricky because one test can always affect other tests by leaving junk behind in the database/collection. Even if your tests don’t explicitly rely on one another, they may still interfere with one another, especially if one of them fails.

    Where possible, use a fresh instance for each test, or wipe the data, ideally in as simple a way as possible – e.g. for a database, wiping an entire table is more likely to succeed than a very specific deletion that you might accidentally get wrong.

    Update: It’s usually better to wipe data at the start of the test, so one failed test run doesn’t affect the next run.

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

Sidebar

Related Questions

I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
I have a simple unit test case (extensive question here ) on a configuration
This has been moved to a test case here . RE-DONE: I want to
I have the following test case that I want to post a piece of
I have a Selenium test case that enters dates into a date selector made
today I have coded a test case for my application, to see how transactions
I have a Boost unit test case which causes the object under test to
I have recorded a very simple test case Using the Selenium IDE integrated with
This is a minimal test case of some code that I actually have. It
I have been suggested to use should:rise in my test case to test for

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.