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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:38:50+00:00 2026-06-15T14:38:50+00:00

I have two classes Calculator1 and Calculator2 which are in the package called com.zzy.junit.user

  • 0

I have two classes Calculator1 and Calculator2 which are in the package called com.zzy.junit.user under the src folder. I use myeclipse to create two test classes to test them respectively. When I execute the one test class among them, how does Junit4 know which class is tested?

Class 1

package com.zzy.junit.user;

public class Calculator1 {

    private int a;
    private int b;

    public Calculator1(int a,int b)
    {
        this.a = a;
        this.b = b;
    }

    public int add()
    {
        return a+b;
    }
}

Class 2

package com.zzy.junit.user;

public class Calculator2{

    public int divide(int a,int b)
    {
        return a/b;
    }
}

And two test classes as follows:
They are both in the src folder called test

Test Class 1

package com.zzy.junit.user;

import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;  

import org.junit.Test;

public class TestCalculator1 {

    @Test
    public void testAdd() {
        Calculator1 s = new Calculator1(3,6);
        int z = s.add();
        assertThat(z,is(9));
    }

}

Test Class 2

package com.zzy.junit.user;

import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;

import org.junit.Test;

public class TestCalculator2 {

    @Test
    public void testDivide() {
        TestCalculator2 t = new TestCalculator2();
        int z = t.divide(4, 2);
        assertThat(z,is(2));
    }

}

I want to know if I execute the test class called TestCalculator2, how does Junit4 know I do want to test Calculator1 class. Is it related to the name of the test class?

  • 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-15T14:38:51+00:00Added an answer on June 15, 2026 at 2:38 pm

    JUnit is a framework for executing tests that can pass or fail. The fact that a single test typically focusses on a single class is a convention observed by most Java programmers. JUnit4 doesn’t know which classes are being tested, it merely executes all methods annotated with @Test.

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

Sidebar

Related Questions

I have two classes which is in different packages (folder). How can I call
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes called Person and Animal that have a lot of methods
I have two classes. UserModel and UserController. file: localhost/controllers/user.controller.php <?php class UserController { public
I have two classes which depend on each other. I've solved this problem before
I have two classes which need to be in same xml file. The way
I have two classes in same package. i have declared a static variable in
i have two classes which have some common methods like funcA(), funcB() and some
I have two classes AbstractWorkFlow ProductionWorkFlow AbstractWorkFlow has fully implemented method executeWorkFlow which I
I have two classes both define under QDialog class. Both classes individually are working

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.