Unable to load a Suite class. This could be due to an error in your runpath

11,503 views
Skip to first unread message

Atiq Sayyed

unread,
Jun 27, 2013, 4:07:43 AM6/27/13
to scalate...@googlegroups.com
Hello,



I'm Having the same trouble :- when i'm running a test written in testng with scala test.


My Source code:-

Scala File
MyTest.scala

package scala

import org.scalatest.testng.TestNGSuite
import java.TestClass

class MyTest extends TestClass with TestNGSuite 

Java File

TestClass.java

package java;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class TestClass {

// create a WebDriver
WebDriver driver;

// use the Firefox browser and go to the wikipedia site
@BeforeMethod
@BeforeClass
public void setUp() {
driver = new FirefoxDriver();
}

// quit from WebDriver
@AfterMethod
@AfterClass
public void tearDown() {
driver.quit();
}

@Test
public void testFindElements() throws Exception {

// find the About link
WebElement about = driver.findElement(By
.xpath("//*[@id='n-aboutsite']/a"));

// click to the link
about.click();

// wait for 5 seconds
Thread.sleep(5000);

// write out the title of the page in console
System.out.println(driver.getTitle());

}
}




And when i'm running this from eclipse as Scalatest-File It gives the Following error

ERROR:- 

Event:Run Aborted
Message:Unable to load a Suite class. This could be due to an error in your runpath. Missing class: scala.MyTest
Date:Thu Jun 27 12:44:02 IST 2013
Thread:Thread-0
Exception:         java.lang.ClassNotFoundException
java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java.net.URLClassLoader$1.run(URLClassLoader.java:355)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
java.lang.ClassLoader.loadClass(ClassLoader.java:423)
java.lang.ClassLoader.loadClass(ClassLoader.java:356)
org.scalatest.tools.Runner$$anonfun$21.apply(Runner.scala:1470)
org.scalatest.tools.Runner$$anonfun$21.apply(Runner.scala:1469)
scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:264)
scala.collection.immutable.List.foreach(List.scala:318)
scala.collection.TraversableLike$class.filter(TraversableLike.scala:263)
scala.collection.AbstractTraversable.filter(Traversable.scala:105)
org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1469)
org.scalatest.tools.RunnerJFrame$RunnerThread$$anonfun$run$1.apply(RunnerJFrame.scala:1361)
org.scalatest.tools.RunnerJFrame$RunnerThread$$anonfun$run$1.apply(RunnerJFrame.scala:1359)
org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1645)
org.scalatest.tools.RunnerJFrame$RunnerThread.run(RunnerJFrame.scala:1358)


I'm using:-
Ecipse Juno
JDK 7
scalatest_2.10-1.9.1
scala 10.1
testng-6.8.5


Any Help would be appreciated.

Thanks,
Atiq

Bill Venners

unread,
Jun 27, 2013, 9:08:55 AM6/27/13
to scalate...@googlegroups.com
Hi Atiq,

That means that it can't load the test class. You need to either include the test class location on the class path or "run path." ScalaTest will load classes from either the class path or run path, but only *discover* classes on the runpath. Usually you specify the runpath to be wherever your build deposits the class files for your tests. You can specify the runpath in your ant build file either as an attribute:

<scalatest runpath="serviceuitest-1.1beta4.jar:myjini">

Or an separate pathelements:

<scalatest>
    <runpath>
      <pathelement location="serviceuitest-1.1beta4.jar"/>
      <pathelement location="myjini"/>
    </runpath>

I'd be sure the class files for both your test ng tests and new tests you're writing in Scala are on the runpath, though you could alternatively put the ones for the Java testng tests on the class path if you wanted, since those are identified via the testng.xml file and not discovered by ScalaTest.

Bill


--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Bill Venners
Artima, Inc.
http://www.artima.com

Atiq Sayyed

unread,
Jun 27, 2013, 9:38:28 AM6/27/13
to scalate...@googlegroups.com


On Thursday, June 27, 2013 1:37:43 PM UTC+5:30, Atiq Sayyed wrote:
Hello Bill,

    I'm not using ANT for this one, attached is the project folder, which contains two test files, one in scala folder, other one in java. . When i run this from eclipse the error "Unable to load a Suite class. This could be due to an error in your runpath. Missing class: scala.MyTest" comes. . 
It will be appreciated if you can show me how to run the test cases in scala folder in above attachment..

Thanks Bill. .
ScalaTest.tar.gz

Chee Seng Chua

unread,
Jun 27, 2013, 10:33:47 AM6/27/13
to scalate...@googlegroups.com
Hi Atiq, 

I tried your attached project in eclipse, the project does not seems to compile even after I added scalatest_2.10-1.9.1.jar, selenium-java-2.33.0.jar and testng-6.8.5.jar in the lib folder, it still has 1 compilation error like this:

error while loading ITestContext, class file '.../testng-6.8.5 ...'

I think it is caused by the testng's own dependencies, it is always tedious task to download and add old the dependencies jar manually by hand, especially when you use selenium.  One solution is to use sbt's sbteclipse plugin to generate the eclipse file, as what I attached.  After extract it you can navigate to the directory, go into sbt prompt and type:

> eclipse

It should generate the eclipse's .project and .classpath file, you could then import the project into Eclipse and try to run the test again.

Hope this help.

Chee Seng




--
ScalaTest2.zip

Atiq Sayyed

unread,
Jun 28, 2013, 12:18:49 AM6/28/13
to scalate...@googlegroups.com
Hey Chua Chee Seng,


   I'm able to run this fine from SBT Command line, but when i import this project to eclipse and if i try to run this it gives me this error.

   Error: Could not find or load main class org.scalatest.tools.Runner

Still not able to get why is it so. .

Chee Seng Chua

unread,
Jun 28, 2013, 12:23:23 AM6/28/13
to scalate...@googlegroups.com
Hi Atiq, 

That's weird, can you print screen what you got under Libraries tab in Java Build Path setting?  Just need to be sure scalatest jar with correct Scala version is in the generated eclipse project's Libraries dependency.

Cheers, 
Chee Seng

Atiq Sayyed

unread,
Jun 28, 2013, 1:35:57 AM6/28/13
to scalate...@googlegroups.com
Hey Chee Seng,

  Attacched is the screen shot of the library, as the library was big, i couldn't capture it in one Screen. . 


Thanks,
Atiq
PrintScr1.png
PrintScreen2.png

Chee Seng Chua

unread,
Jun 28, 2013, 2:11:17 AM6/28/13
to scalate...@googlegroups.com
Hi Atiq, 

It seems correct, scalatest_2.10-2.0.M5b.jar is in it.  Hmm, can you check Run Configuration that you are running also?  Check if the Run Configuration has the correct project and Classpath too?

Chee Seng




Thanks,
Atiq

--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.

Atiq Sayyed

unread,
Jun 28, 2013, 2:54:26 AM6/28/13
to scalate...@googlegroups.com

Hi, 

  There was a problem in Run Configuration path, when i corrected that i got this error:- 

WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all uses of -p to -R.
*** RUN ABORTED ***
  java.lang.ClassNotFoundException: test.scala.MyTest
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
  at org.scalatest.tools.Runner$$anonfun$22.apply(Runner.scala:1962)
  at org.scalatest.tools.Runner$$anonfun$22.apply(Runner.scala:1960)
  at scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:264)
  at scala.collection.immutable.List.foreach(List.scala:318)
  ...

Chee Seng Chua

unread,
Jun 28, 2013, 3:08:23 AM6/28/13
to scalate...@googlegroups.com
Hi Atiq, 

From the project you sent me yesterday, the suite class name should be MyTest (since you didn't declare any package), not test.scala.MyTest.

Chee Seng


Atiq Sayyed

unread,
Jul 1, 2013, 7:12:45 AM7/1/13
to scalate...@googlegroups.com
OOps sorry, was my badd!!!. . .


The Run path was different. . .

it was the error in run configuration

Thanks,
Atiq 

Chee Seng Chua

unread,
Jul 1, 2013, 8:11:40 AM7/1/13
to scalate...@googlegroups.com
Hi Atiq, 

No problem, great that you work it out!

Cheers, 
Chee Seng


--
Reply all
Reply to author
Forward
0 new messages