尝试使用TestNG测试java应用程序的异常

时间:2013-09-17 14:29:45

标签: java spring maven testng ocmockito

我正在使用maven-java-spring和testNG,在测试流视图之前,一切似乎都很好。我正在尝试解决此异常,我正在寻找,并且我发现了一些不同的版本但我不相信这个答案,让我展示一个例外:

Listening for transport dt_socket at address: 8000
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.UnsupportedClassVersionError: cat/base/gpt/ui/ConsultaDeutesTest : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.maven.surefire.util.DefaultScanResult.loadClass(DefaultScanResult.java:131)
        at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:95)
        at org.apache.maven.surefire.testng.TestNGProvider.scanClassPath(TestNGProvider.java:158)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:103)
        ... 9 more

如果有人需要更多信息,我将被征集以显示它(信息):)

我有更多信息

在测试类中失败的方法是: @Test

public void comprovarCercaBuuida(){
    /*Objecte que contindrà l'info de la cerca*/
    DeuteBackBean deuteBB;

    List<IDeute> respostaDeutesExe = new ArrayList<IDeute>();
    List<IDeute> respostaDeutesVol = new ArrayList<IDeute>();
    List<IDeute> respostaDeutesTots = new ArrayList<IDeute>();

    /*tot els paràmetres del servei s'han de passar com a mockito!!!*/
    Mockito.when(serveiGpt.obtenirDeutes(Mockito.eq(CLAU_SUBJECTE_BUIT),Mockito.eq(E_TIPUS_DEUTE_HIS),Mockito.eq(PERIODE_DEUTE_EXE))).thenReturn(respostaDeutesExe);
    **startFlow(context)**-->why??? 
    assertCurrentStateEquals(ID_VISTA_FORMULARI_CERCA);
    Mockito.when(serveiGpt.obtenirDeutes(Mockito.eq(CLAU_SUBJECTE_BUIT),Mockito.eq(E_TIPUS_DEUTE_HIS),Mockito.eq(PERIODE_DEUTE_VOL))).thenReturn(respostaDeutesVol);


    Mockito.when(serveiGpt.obtenirDeutes(Mockito.eq(CLAU_SUBJECTE_BUIT),Mockito.eq(E_TIPUS_DEUTE_HIS),Mockito.eq(PERIODE_DEUTE_TOTS))).thenReturn(respostaDeutesTots);

    }

并抛出:

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.906 sec <<< FAILURE!
comprovarCercaBuuida(cat.base.gpt.ui.ConsultaDeutesTest)  Time elapsed: 0.047 sec  <<< FAILURE!
java.lang.NullPointerException
        at cat.base.baseframe.test.swf.AbstractExternalizedFlowExecutionTestNG.buildFlow(AbstractExternalizedFlowExecutionTestNG.java
:158)
        at cat.base.baseframe.test.swf.AbstractExternalizedFlowExecutionTestNG.getFlowDefinition(AbstractExternalizedFlowExecutionTes
tNG.java:135)
        at cat.base.baseframe.test.swf.AbstractFlowExecutionTestNG.startFlow(AbstractFlowExecutionTestNG.java:88)
        at cat.base.baseframe.test.swf.AbstractFlowExecutionTestNG.startFlow(AbstractFlowExecutionTestNG.java:77)
        at cat.base.gpt.ui.ConsultaDeutesTest.startFlow(ConsultaDeutesTest.java:117)
        at cat.base.gpt.ui.ConsultaDeutesTest.comprovarCercaBuuida(ConsultaDeutesTest.java:105)

INFO  GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@1df8b99: display name [org.sp
ringframework.context.support.GenericApplicationContext@1df8b99]; startup date [Tue Sep 17 17:00:54 CEST 2013]; root of context hiera
rchy
INFO  DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2f8b
5a: defining beans [org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotat
ion.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework
.context.annotation.internalRequiredAnnotationProcessor,serveiTip,serveiGpt,sessio,usuari,consultaDeutes]; root of factory hierarchy

Results :

Failed tests:   comprovarCercaBuuida(cat.base.gpt.ui.ConsultaDeutesTest)

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

我认为“上下文”是空的?但我不明白..

/ **每个执行的上下文* /

protected MockExternalContext context = new MockExternalContext();

0 个答案:

没有答案