title: Test class can only have one constructor
body: <p>Anybody encountered this error</p>
  
  <p>initializationError(junit.framework.TestSuite): Test class can only have one constructor</p>
  
  <p>Use Case.</p>
  
  <p>I have 2 TestScripts in a TestSuite. If I dynamically create the TestSuite and then add the 2 testScripts and invoke this</p>
  
  <pre><code>Result result = JUnitCore.runClasses(clazz);
  </code></pre>
  
  <p>where clazz is the TestSuite class.</p>
  
  <p>However I if invoke the JUnitCore.runClasses on each 2 TestScripts there is no problem.</p>
  
  <p>I used JUnit3. </p>
  
  <p>I have similar question with this <a href="https://stackoverflow.com/questions/9415325/junit-error-illegalargumentexceptiontest-class-can-only-have-one-constructor">JUnit error - IllegalArgumentException:Test class can only have one constructor</a>, but mine involves creating the test suite class dynamically. Reason being is that there is a usecase that I could just include 1 testscript in a testsuite or i could have 2 testscripts in a testsuite.</p>
  
  <p><strong>UPDATE code:</strong></p>
  
  <pre><code>public class ScriptTest1 extends TestCase { 
      private ScriptTest1() { }   
      public void testMethod1() {
          Assert.assertEquals(true, true);
      }
  }
  
  public class ScriptTest2 extends TestCase { 
      private ScriptTest2() { }   
      public void testMethod2() {
          Assert.assertEquals(true, true);
      }
  }
  </code></pre>
  
  <p>Then in another class</p>
  
  <pre><code>File file = new File("file to ScriptTest.class");
  Class&lt;?&gt; clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
  
  //construct a new test suite
  TestSuite ts = new TestSuite("Sample Test Suite with only ScriptTest1");
  ts.addTestSuite((Class&lt;? extends TestCase&gt;) clazz);
  
  Result result = JUnitCore.runClasses(ts.getClass());
  HashSet&lt;String&gt; failureMethod = new HashSet&lt;String&gt;();
  for (Failure failure : result.getFailures()) {
       System.out.println("Failure: " + failure.toString());      
  }
  </code></pre>
  
  <p>Failure will output: initializationError(junit.framework.TestSuite): Test class can only have one constructor
  However if I just directly do this, it will run fine.</p>
  
  <pre><code>File file = new File("file to ScriptTest.class");
  Class&lt;?&gt; clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
  Result result = JUnitCore.runClasses(clazz);
  </code></pre>
  
  <p>I created the test classes in JUnit4 and Im running my main program with dependency on JUnit4 also.</p>