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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:08:59+00:00 2026-05-30T05:08:59+00:00

Unit testing is new to me, and I have this error I don’t understand.

  • 0

Unit testing is new to me, and I have this error I don’t understand.
I have 2 TestCases subclasses that work fine when ran standalone, but not in my test suite.

In the test suite (AllTest class below), the first 3 work fine, but AvailableResouresTest and ModelTest generate the error.

I suspect it has to do with the fact that I had to import those 2 classes (and only them) in AllTest whereas they are all located in the same package.

I used the Eclipse wizard to create those two test cases. However, I can’t find noticeable differences in the code, so may be some fresh eye can help. Thank you very much

The test suite code:

package com.tms.client.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.tms.client.model.AvailableResources;  // I have to import those 2 classes only
import com.tms.client.model.Model;               // but all my tests are in the same folder

@RunWith(Suite.class)
@SuiteClasses(value = { TaskTest.class, 
                    ResourceTest.class,
                    DateForTMSTest.class,
                    AvailableResources.class,
                    Model.class})
public class AllTests{
public static final String SCHEME_FILENAME= "config/project_schema.inc2.xsd";
public static final String RESOURCE_FILENAME = "config/resourceList.inc2.txt";
public static final String PROJECT_FILENAME = "input/project.inc2.e.xml";
public static final String PROJECT_FILENAME_SAVE_LOCATION =     "input/project.save.tmp.xml";
}

The non working test:

package com.tms.client.tests;
import java.util.ArrayList;
import java.util.Hashtable;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import com.tms.client.model.AvailableResources;
import com.tms.client.model.Model;
import com.tms.client.model.ParseXML;
import com.tms.client.model.Task;

public class AvailableResourcesTest extends TestCase{

ArrayList<String> stringsFromFile;
Class<AvailableResources> dummyAR;
Model model;

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    super.setUp();
    ParseXML.setSchemaFile(AllTests.SCHEME_FILENAME);
    model = new Model(AllTests.RESOURCE_FILENAME, AllTests.PROJECT_FILENAME);
    dummyAR = AvailableResources.class;
    stringsFromFile = Helper.getLinesFromFile(AllTests.RESOURCE_FILENAME);
}

@SuppressWarnings("unchecked")
@Test
public void testFlushAllResources() {
    //Get the size BEFORE flushing
    Hashtable<Integer,Task> mapIdToObject = (Hashtable<Integer,Task>) PrivateAccessor.getPrivateFieldStatic(dummyAR, "mapIDtoName");
    int sizeBeforeFlush = mapIdToObject.size();
    // Flush tasks
    PrivateAccessor.invokePrivateMethodStatic(dummyAR, "flushAllResources", null);
    // Get the size AFTER flushing
    mapIdToObject = (Hashtable<Integer,Task>) PrivateAccessor.getPrivateFieldStatic(dummyAR, "mapIDtoName");
    int sizeAfterFlush = mapIdToObject.size();
    boolean test = sizeBeforeFlush > 0 && sizeAfterFlush == 0;  
    // Add code to remove task
    assertTrue(test);       
}

/**
 * Compare # lines in resource file with mapIdToName.size()
 */
@Test
public void testSize() {
    Hashtable<Integer,Task> mapIdToName = (Hashtable<Integer,Task>) PrivateAccessor.getPrivateFieldStatic(dummyAR, "mapIDtoName");
    assertEquals(mapIdToName.size(), stringsFromFile.size());
}

/**
 * Check that every resource id from file is available in model
 */
@Test
public void testIsAvailable() {
    for(String s: stringsFromFile){
        int resourceId = Integer.parseInt(s.split(";")[0]); // the resourceId from file
        assertTrue(AvailableResources.isAvailable(resourceId));
    }
}

/**
 * Check that the name returned corresponds to the name in file
 */
@Test
public void testGetNameFromID() {
    for(String s: stringsFromFile){
        int resourceId = Integer.parseInt(s.split(";")[0]); // the resourceId from file
        String resourceName = s.split(";")[1]; // the resourceId from file
        assertEquals(AvailableResources.getNameFromID(resourceId), resourceName);
    }
}

@Test
public void testAddNameByID() {
    fail("Not yet implemented");

}

@Test
public void testRemoveResourceByID() {
    fail("Not yet implemented");
}
}

And the stack trace:

java.lang.IllegalArgumentException: Test class can only have one constructor
at org.junit.runners.model.TestClass.<init>(TestClass.java:37)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:98)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
at org.junit.runners.Suite.<init>(Suite.java:101)
at org.junit.runners.Suite.<init>(Suite.java:67)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:35)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  • 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-30T05:09:00+00:00Added an answer on May 30, 2026 at 5:09 am

    If you are using JUnit4 your classes shouldn’t extend TestCase, you just need the annotation @Test before your test methods.

    And your test suite should begin like this:

    @RunWith(Suite.class)
    @SuiteClasses({TaskTest.class, 
                    ResourceTest.class,
                    DateForTMSTest.class,
                    AvailableResources.class,
                    Model.class})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently looking into unit testing for a new application I have to create.
I am new to Unit Testing and think I might have dug myself into
I am new to unit testing. I have done unit testing on controller classes
I'm new to unit testing. But how do I unit test my DAL which
I'm new to unit testing and nUnit (2.48). I'd like to write a test
I'm new to unit testing using nunit (and Java development in general). When creating
I am new to unit testing, and would like to know how you would
I'm new to unit testing and NUit in particular. I'm just typing some examples
I'm new to Unit Testing, and I'm only getting into the routine of building
I'm still new to Unit testing, and specifically PHPUnit as the testing framework. Suppose

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.