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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:04:21+00:00 2026-05-14T01:04:21+00:00

I have two classes that I am testing (let’s call them ClassA and ClassB).

  • 0

I have two classes that I am testing (let’s call them ClassA and ClassB). Each has its own JUnit test class (testClassA and testClassB respectively).

ClassA relies on ClassB for its normal functioning, so I want to make sure ClassB passes its tests before running testClassA (otherwise the results from testClassA would be meaningless).

What is the best way to do this? In this case it is for an assignment so I need to keep it to the two specified test classes if possible.

Can/should I throw an exception from testClassA if testClassB’s tests aren’t all passed? This would require testClassB to run invisibly and just report its success/failure to testClassA, rather than to the GUI (via JUnit).

I am using Eclipse and JUnit 4.8.1

Update: So far the best I’ve managed is a separate file with a test suite as shown below. This is still not quite what I’m after as it still allows ClassB tests to be run if ClassA fails some tests.

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({testClassA.class, testClassBCode.class})
public class testClassB {
}
  • 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-14T01:04:22+00:00Added an answer on May 14, 2026 at 1:04 am

    Your unit tests should not depend on other tests.

    One solution for your problem would be to mock ClassB in your ClassA’s tests, in order to test its behaviour independently of the results of ClassB’s tests.

    I recommend you give mockito a try!

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

Sidebar

Ask A Question

Stats

  • Questions 524k
  • Answers 524k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your program works fine if you run it with no… May 16, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer Here's a solution that satisfies the second query in linear… May 16, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer If the unstored fields were stored… they'd be called stored… May 16, 2026 at 9:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

My development team has started to use Mockito and have classes that have been
I have two classes that are almost identical, besides one method. The classes have
I have two C# classes that have many of the same properties (by name
I have two classes. Looking to be able to grab a variable that is
In a WCF service, I have two classes with the [DataContract] attribute. One of
I have two Java class hierarchies that share a common ancestor and implement a
I have two classes A and B , and an implicit conversion operator exists
I have two classes. One is a management class, which stores a bunch of
I have two classes: public class DocumentViewModel { public virtual string DocumentNumber { get;
I want to let programmers and myself know that a method does not want

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.