2013-01-17 88 views
0

,當我得到這個錯誤:Junit的錯誤嘗試運行單元測試

Class not found com.apache.camel.example.tests.ReportIncidentRoutesTest 
java.lang.ClassNotFoundException: com.apache.camel.example.tests.ReportIncidentRoutesTest 
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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429) 
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) 

這對於我收到了新的錯誤更新的堆棧跟蹤。在運行配置我確實指向這個類,所以我不知道爲什麼我仍然得到這個錯誤。

編輯:-------------------------------------------- --------------------------------------- 我的測試等級副本:

package com.apache.camel.example.tests; 

import org.apache.camel.CamelContext; 
import org.apache.camel.example.reportincident.InputReportIncident; 
import org.apache.camel.example.reportincident.OutputReportIncident; 
import org.apache.camel.example.reportincident.ReportIncidentEndpoint; 
import org.apache.camel.example.reportincident.ReportIncidentRoutes; 
import org.apache.camel.impl.DefaultCamelContext; 
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 
import org.jvnet.mock_javamail.Mailbox; 

import junit.framework.Test; 
import junit.framework.TestCase; 
我們的路線

/** * 單元測試 */

public class ReportIncidentRoutesTest extends TestCase { 

private CamelContext camel; 

// should be the same address as we have in our route 
private static String ADDRESS = "http://localhost:8080/part-five/webservices/incident"; 

protected void startCamel() throws Exception { 
    camel = new DefaultCamelContext(); 
    camel.addRoutes(new ReportIncidentRoutes()); 
    camel.start(); 
} 

protected static ReportIncidentEndpoint createCXFClient() { 
    // we use CXF to create a client for us as its easier than JAXWS and works 
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 
    factory.setServiceClass(ReportIncidentEndpoint.class); 
    factory.setAddress(ADDRESS); 
    return (ReportIncidentEndpoint) factory.create(); 
} 

public void testRendportIncident() throws Exception { 
    // start camel 
    startCamel(); 

    // assert mailbox is empty before starting 
    Mailbox inbox = Mailbox.get("[email protected]"); 
    assertEquals("Should not have mails", 0, inbox.size()); 

    // create input parameter 
    InputReportIncident input = new InputReportIncident(); 
    input.setIncidentId("123"); 
    input.setIncidentDate("2008-08-18"); 
    input.setGivenName("Patrick"); 
    input.setFamilyName("joe"); 
    input.setSummary("Blah"); 
    input.setDetails("Blah blah"); 
    input.setEmail("[email protected]"); 
    input.setPhone("845 2962 7576"); 

    // create the webservice client and send the request 
    ReportIncidentEndpoint client = createCXFClient(); 
    OutputReportIncident out = client.reportIncident(input); 

    // assert we got a OK back 
    assertEquals("0", out.getCode()); 

    // let some time pass to allow Camel to pickup the file and send it as an email 
    Thread.sleep(3000); 

    // assert mail box 
    assertEquals("Should have got 1 mail", 1, inbox.size()); 

    // stop camel 
    camel.stop(); 
} 

}

+0

你如何運行單元測試?你如何構建你的發佈罐? – Taky

+0

我只是在做一個eclipse運行 - > JUnit Test – parchambeau

+0

而我的發佈jar會打包在一個WAR文件中部署到一個tomcat服務器 – parchambeau

回答

0

看來JUnit 3中在classpath編譯時(假設你沒有得到compil任何使用junit api的錯誤),但不是在運行時,所以會出現一些類路徑不匹配的情況。

看來你運行通過eclipse測試亞軍的測試,是配置爲相同的junit版本作爲測試寫入?

+0

是的,我得到一個不同的錯誤之前,我看了在運行配置中發現它已被設置爲JUNIT 4,因此我將其更改爲3,但隨後此錯誤開始彈出。 – parchambeau

+0

我猜想eclipse配置對junit 3 .jar文件有一個不好的路徑,但我不知道如何找到並修復該配置,對不起。 –

相關問題