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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:09:41+00:00 2026-06-15T09:09:41+00:00

I have two files: Calc.java public class Calc { public int add(int a, int

  • 0

I have two files:

Calc.java

public class Calc {
 public int add(int a, int b) {
  return a + b;
 }
 public int subtract(int a, int b) {
  return a - b;
 }
}

and TestCalc.java

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

public class TestCalc {

  Calc c = new Calc();

  @Test
  public void testSum() {
    // 6 + 9 = 15
    int expected = 15;
    int actual = c.add(6, 9);
    assertEquals("adding 6 and 9", expected, actual);
  }

  @Test
  public void testSubstr() {
    // 18 - 3 = 15
    int expected = 15;
    int actual = c.subtract(18, 3);
    assertEquals("subtracting 3 from 18", expected, actual);
    }
  }

They compile without errors:

javac -cp .:junit-4.11.jar TestCalc.java
javac -cp .:junit-4.11.jar Calc.java

But when I’m trying to run, I’m getting an error:

java -cp .:junit-4.11.jar TestCalc

Exception in thread "main" java.lang.NoSuchMethodError: main

Could someone, please, explain why? And how to fix that?

  • 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-15T09:09:42+00:00Added an answer on June 15, 2026 at 9:09 am

    You should use the JUnit’s runners to run the test case classes.

    java -cp .:junit-4.11.jar org.junit.runner.JUnitCore TestCalc.java
    

    JUnitCore will run the tests in your test class.

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

Sidebar

Related Questions

I have two files: public interface PrintService { void print(PrintDetails details); class PrintDetails {
I have two files testable.py: def joiner(x,y): return x+y test_testable.py: import unittest import testable
I am new to java and I have two classes (class calc and button)
I have the following two script files (i.e., formtest.html and calc.php). When I do
I have two files: Test.java Other.java I wanted to learn how to call the
I have two files: a.py b.py How can I access my ABC123 class defined
I have two files: template.php: <div><?php echo $myVar; ?></div> controller class MyClass extends Base
I have two files client.php and server.php. The client file send a HTTP request
I have two files: domainList and config.cnf. The domainList file simply has a list
I have two files 1 - index.php 2 - main.php index.php call to main.php

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.