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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:22+00:00 2026-06-18T00:15:22+00:00

I am currently developing a program that can execute JUnit test cases on external

  • 0

I am currently developing a program that can execute JUnit test cases on external classes. These external classes are sent in by students and we would like to evaluate them.

I have the following test case

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

public class Task1Test {

    @Test
    public void testAdd() {
        Task1 t = new Task1();
        int a = 5;
        int b = 11;
        assertEquals("Wrong add result", a+b, t.add(a,b));
    }
}

and I compiled it with:
$ javac -cp .:../lib/junit/junit-4.11.jar Task1Test.java

The Task1 will be a student’s class, but for now it is just a sample class with an add method that will return a wrong result. The file Task1.java is located in the same folder as Task1Test.java.

In my program I load the test case class and try to run it with JUnitCore:

String testsPath = "/path/to/classes";
String junitJar = "/path/to/junit-4.11.jar"
URL taskUrl = new File(testsPath).toURI().toURL();
URL[] urls = new URL[] {taskUrl,junitJar};

@SuppressWarnings("resource")
ClassLoader loader = new URLClassLoader(urls);
Class<?> clazz = loader.loadClass(task);

Result res = JUnitCore.runClasses(clazz);

if(!res.wasSuccessful()) {
    for(Failure f : res.getFailures()) {
        System.out.println(f.toString());
    }
}

However, it does not work as expected. When I run this code, I get this message:
initializationError(Task1Test): No runnable methods

When I look into the loaded class using reflections, I can see that the method testAdd has no annotation (i.e. method.getAnnotation(org.junit.Test.class) returns null).

Does anyone have an idea? Did I forget a compiler switch or anything?

I am using Java 1.7.0_11 and the code is run in an web application on Glassfish 3.1.2.2

EDIT:

I can run the test case from command line with:
$ java -cp .:../../code/lib/junit/junit-4.11.jar:../../code/lib/junit/hamcrest-core-1.3.jar org.junit.runner.JUnitCore Task1Test

  • 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-18T00:15:24+00:00Added an answer on June 18, 2026 at 12:15 am

    I found a solution from this answer
    I did not set a parent class loader, which seems to have caused the trouble. Setting it as it was said in the other answer it now executes the test.

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

Sidebar

Related Questions

I'm currently developing a percussion tutorial program. The program requires that I can determine
I am currently developing a program that uses C#'s Dictionary container (specifically, SortedDictionary). This
I'm currently developing a program that will generate reports based upon lead data. My
I'm currently developing a C program that needs to parse some bespoke data structures,
I am currently developing a program (C++ Win32, Visual Studio 2012) that captures audio
We're currently developing some functionality for our program that needs OpenCV. One of the
I am currently developing a program that must handle multiple threads. When I start
I am currently developing an android program. After some searching i can't seem to
I am currently developing my program using sample BluetoothChat program on android device. This
I'm currently developing a web application based on jQuery Mobile. I would like to

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.