2013-02-04 52 views
0

我是JUnit和硒服务器的新手,因此我非常感谢他们的帮助。JUnit找不到类

我运行Ubuntu 12与Java 7和硒IDE和服务器。我用selenium IDE创建了一个简单的登录测试脚本,并将其导出到Java/Junit4/webdriver。

我然后使用以下命令

javac -cp .:/usr/share/java/junit4.jar -cp .:/home/sakamoto/SeleniumServer/selenium-server-standalone-2.28.0.jar LoginTest.java 

这似乎经历没有任何错误(或终端为此事的任何消息)编译的脚本。

尝试运行从硒IDE生成单元测试导出到JUnit4 webdriver的,当我看到这个错误:

java -cp /home/sakamoto/SeleniumServer/selenium-server-standalone-2.28.0.jar org.junit.runner.JUnitCore com.example.tests.LoginTest 
JUnit version 4.11 
Could not find class: com.example.tests.LoginTest 

Time: 0.001 

OK (0 tests) 

[email protected]:~/Workspace$ 

我也有我的.bashrc文件的末尾以下行,是能够用junit4运行样本测试。

export CLASSPATH=.:/usr/share/java/junit4.jar 
export CLASSPATH=.:/usr/share/java/junit.jar 

那么......我该如何摆脱无法找到类:问题并运行脚本?

回答

1

看来,JUnit的找不到类路径的LoginTest.class文件。

假设你有一个这样的目录结构:

/home/sakamoto/my-project/com/examples/tests/LoginTest.class 

然后,尝试明确包括路径到classpath里面my-project目录。例如,试试这个:

java -cp /home/sakamoto/SeleniumServer/selenium-server-standalone-2.28.0.jar:/home/sakamoto/my-project org.junit.runner.JUnitCore com.example.tests.LoginTest 

我认为JUnit是使用类路径+包名称确定LoginTest测试的位置。我猜/希望JUnit会1)发现/home/sakamoto/my-project在classpath中,它会2)追加包目录com/examples/tests,这样它看起来LoginTest.class内/home/sakamoto/my-project/com/examples/tests

这已经有一段时间,因为我用硒,不幸的是,我没有硒设置或我想测试这个!但希望是有效的。

+0

这似乎没有工作。我遇到同样的问题。 :( –

+0

尝试使用包含LoginTest.class的目录的完整绝对路径:java -cp /home/sakamoto/SeleniumServer/selenium-server-standalone-2.28.0.jar:/home/sakamoto/**change this你的路径**/com/example/tests org.junit.runner.JUnitCore com.example.tests.LoginTest' – Upgradingdave

+0

这似乎并不奏效。是否还有其他的东西导致系统无法找到它?我可以在java代码中取出包行,但是当我尝试运行它时,我得到了相同的结果 –