2013-02-04 54 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代碼中取出包行,但是當我嘗試運行它時,我得到了相同的結果 –