"About using Springjunit4classrunner Unit test error problem"

Source: Internet
Author: User

Today, the unit tests the following code to find that the project always error:

 PackageCom.yhb.jsxn.service;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;ImportJava.util.HashMap;Importjava.util.List;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.test.context.ContextConfiguration;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;Importcom.yhb.jsxn.entity.AccountsPastTable; the @RunWith (Springjunit4classrunner.class) @ContextConfiguration ({"Classpath:applicationcontext*.xml"}) Public classTestservice {protected Static FinalLogger LOG = Loggerfactory.getlogger (testservice.class); @AutowiredPrivateAccountspasttableservice Accountspasttableservice; @Test Public voidTest () {HashMap<string, string> parms =NewHashmap<string,string>(); Parms.put ("UserId", "Bb7534e3-4f35-4ff1-b930-ccc962c45def"); List<AccountsPastTable> list = Accountspasttableservice.selectbyuseridandtime (parms);//Ascending order        intCountday = 0;//consecutive days        intTimes = 0;//number of drawsCalendar Calendar =calendar.getinstance ();  for(inti = 0; I < List.size ()-1; i++) {calendar.settime (List.get (i). Getpasttime ()); intBefore =Calendar.get (calendar.day_of_year); Calendar.settime (List.get (i+1). Getpasttime ()); intafter =Calendar.get (calendar.day_of_year); if((after-before) = = 1) {Countday++; if(Countday = = 3) { times++; Countday-=3; }            }Else{countday= 0; }} System.out.println ("Draw Times" +Times ); }}
Statistics Draw Number

java.lang.IllegalStateException:Failed to load ApplicationContext
At Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext ( CACHEAWARECONTEXTLOADERDELEGATE.JAVA:99)
At Org.springframework.test.context.TestContext.getApplicationContext (testcontext.java:122)
At Org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary ( servlettestexecutionlistener.java:105)
At Org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance ( servlettestexecutionlistener.java:74)
At Org.springframework.test.context.TestContextManager.prepareTestInstance (testcontextmanager.java:312)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest (springjunit4classrunner.java:211)
At Org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall ( springjunit4classrunner.java:288)
At Org.junit.internal.runners.model.ReflectiveCallable.run (reflectivecallable.java:15)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock (springjunit4classrunner.java:284 )
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:231)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:88)
At Org.junit.runners.parentrunner$3.run (parentrunner.java:231)
At Org.junit.runners.parentrunner$1.schedule (parentrunner.java:60)
At Org.junit.runners.ParentRunner.runChildren (parentrunner.java:229)
At org.junit.runners.parentrunner.access$000 (parentrunner.java:50)
At Org.junit.runners.parentrunner$2.evaluate (parentrunner.java:222)
At Org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate ( RUNBEFORETESTCLASSCALLBACKS.JAVA:61)
At Org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate ( RUNAFTERTESTCLASSCALLBACKS.JAVA:71)
At Org.junit.runners.ParentRunner.run (parentrunner.java:300)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run (springjunit4classrunner.java:174)
At Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (junit4testreference.java:86)
At Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:459)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192)
Caused by:org.springframework.beans.factory.BeanDefinitionStoreException:Failed to read candidate component Class:file[C:\temp\p2p_yhb\build\classes\com\yhb\jsxn\apppush\android\AndroidBroadcast.class]; Nested exception is Org.springframework.core.NestedIOException:ASM Classreader failed to parse class file-probably due To a new Java class file version that isn ' t supported Yet:file [C:\temp\p2p_yhb\build\classes\com\yhb\jsxn\apppush\androi D\androidbroadcast.class]; Nested exception is java.lang.IllegalArgumentException
At Org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents ( classpathscanningcandidatecomponentprovider.java:290)
At Org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan ( classpathbeandefinitionscanner.java:242)
At Org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse ( componentscanbeandefinitionparser.java:84)
At Org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse (namespacehandlersupport.java:73)
At Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( beandefinitionparserdelegate.java:1438)
At Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( beandefinitionparserdelegate.java:1428)
At Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions ( defaultbeandefinitiondocumentreader.java:185)
At Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions ( defaultbeandefinitiondocumentreader.java:139)
At Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions ( defaultbeandefinitiondocumentreader.java:108)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions ( xmlbeandefinitionreader.java:493)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( xmlbeandefinitionreader.java:390)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:334)
At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:302)
At Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:174)
At Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:209)
At Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:180)
At Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:243)
At Org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions ( abstractgenericcontextloader.java:233)
At Org.springframework.test.context.support.AbstractGenericContextLoader.loadContext ( abstractgenericcontextloader.java:117)
At Org.springframework.test.context.support.AbstractGenericContextLoader.loadContext ( ABSTRACTGENERICCONTEXTLOADER.JAVA:60)
At Org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading ( ABSTRACTDELEGATINGSMARTCONTEXTLOADER.JAVA:100)
At Org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext ( abstractdelegatingsmartcontextloader.java:248)
At Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal ( CACHEAWARECONTEXTLOADERDELEGATE.JAVA:64)
At Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext ( cacheawarecontextloaderdelegate.java:91)
... More
Caused By:org.springframework.core.NestedIOException:ASM Classreader failed to parse class file-probably due to a new Java class file version that isn ' t supported Yet:file [C:\temp\p2p_yhb\build\classes\com\yhb\jsxn\apppush\android\ Androidbroadcast.class]; Nested exception is java.lang.IllegalArgumentException
At Org.springframework.core.type.classreading.simplemetadatareader.<init> (SimpleMetadataReader.java:56)
At Org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader ( SIMPLEMETADATAREADERFACTORY.JAVA:80)
At Org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader ( CACHINGMETADATAREADERFACTORY.JAVA:102)
At Org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents ( classpathscanningcandidatecomponentprovider.java:266)
... More
caused by:java.lang.IllegalArgumentException
At org.springframework.asm.classreader.<init> (Unknown Source)
At org.springframework.asm.classreader.<init> (Unknown Source)
At org.springframework.asm.classreader.<init> (Unknown Source)
At Org.springframework.core.type.classreading.simplemetadatareader.<init> (SimpleMetadataReader.java:53)
... Wuyi more

The reason for this finding was that I used the jdk8 lambda expression in the first few days to change the build environment to 1.8. Spring 3.2 does not support the 1.8 compilation environment, the workaround is to reduce to 1.7 compilation environment or replace Spring 3.1

"About using Springjunit4classrunner Unit test error problem"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.