NutzCN Logo
问答 nutzwk junit 打包问题
发布于 2489天前 作者 wx_dc1uhcoqb670vfspa24d 1694 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

正常情况下,将test文件夹下的测试用例注释,clean package 打包项目是没有问题的。

如果我不注释 ,打包的时候忽略test文件夹下的测试用例,这样的思路可以实现吗?

17 回复

测试用例启动时:

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /logs/oms.log (No such file or directory)
	at java.io.FileOutputStream.open0(Native Method)
	at java.io.FileOutputStream.open(FileOutputStream.java:270)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
	at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
	at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
	at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:223)
	at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
	at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
	at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
	at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
	at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
	at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
	at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
	at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547)
	at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
	at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
	at org.apache.log4j.Logger.getLogger(Logger.java:104)
	at org.nutz.log.impl.Log4jLogAdapter$Log4JLogger.<init>(Log4jLogAdapter.java:54)
	at org.nutz.log.impl.Log4jLogAdapter.getLogger(Log4jLogAdapter.java:33)
	at org.nutz.log.Logs.get(Logs.java:57)
	at org.nutz.ioc.impl.NutIoc.<clinit>(NutIoc.java:45)
	at org.nutz.mock.NutTestRunner.createIoc(NutTestRunner.java:67)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:30)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
log4j:ERROR Either File or DatePattern options are not set for appender [file].

配置文件中设置:
log4j.appender.file.File=${catalina.base}/logs/oms.log

test目录下面放个log4j.properties,仅输出到控制台

执行测试用例时,会抛出上面异常,不影响执行过程
但是打包项目是,如果不配置
true
就会打包失败

src/test/resources目录下面放个log4j.properties,仅输出到控制台

执行测试用例,已经成功执行,insert也插入成功,但是日志还有报错

[WARN ] 2018-03-01 17:05:08,220 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:201) - clear cache fail: [product]
java.lang.NullPointerException
	at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.getCache(EhcacheDaoCacheProvider.java:44)
	at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.clear(EhcacheDaoCacheProvider.java:34)
	at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:196)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:159)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:105)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:89)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:75)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:73)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:149)
	at cn.wizzer.framework.base.service.BaseServiceImpl.insert(BaseServiceImpl.java:186)
	at cn.dean.test.GfAuctionTest.testOrder(GfAuctionTest.java:29)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:33)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
[INFO ] 2018-03-01 17:05:08,273 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:286) - org.nutz.ioc.impl.NutIoc@1882395698 is closing. startup date [18-03-01 17:05:02.881]
[DEBUG] 2018-03-01 17:05:08,273 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'deanIdGenerator' ...
[DEBUG] 2018-03-01 17:05:08,273 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'gfProductServiceImpl' ...
[DEBUG] 2018-03-01 17:05:08,273 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'snowflake' ...
[DEBUG] 2018-03-01 17:05:08,273 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'cacheManager' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'cacheProvider' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'cacheExecutor' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'fileSqlManager' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'conf' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'dao' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'gfAuctionTest' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object '$aop_wkcache' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object '$aop_syslog' ...
[DEBUG] 2018-03-01 17:05:08,274 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object '$aop_async' ...
[DEBUG] 2018-03-01 17:05:08,275 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object 'dynamicInterceptor' ...
[DEBUG] 2018-03-01 17:05:08,275 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) - Depose object '$aop_1_plugin' ...
[DEBUG] 2018-03-01 17:05:08,275 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:113) - Depose object 'dataSource' ...
[INFO ] 2018-03-01 17:05:08,280 com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:1514) - {dataSource-1} closed
[INFO ] 2018-03-01 17:05:08,280 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:300) - org.nutz.ioc.impl.NutIoc@1882395698 is deposed. startup date [18-03-01 17:05:02.881]
Disconnected from the target VM, address: '127.0.0.1:50504', transport: 'socket'

Process finished with exit code 0

不好定位问题

[DEBUG] 2018-03-01 17:05:08,200 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - 
  For example:> "INSERT INTO product(id) VALUES('6374902131652038656') "
[WARN ] 2018-03-01 17:05:08,220 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:201) - clear cache fail: [product]

加一句

CacheManager getInstance();

貌似没解决问题,还有别的错误可能吗?

把它写到testcase的静态块里试试,确保比NutDao先初始化

又有个新的问题

org.nutz.ioc.IocException: IocBean[gfAuctionTest] throw Exception when creating

	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:160)
	at org.nutz.mock.NutTestRunner.createTest(NutTestRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:33)
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: IocBean[gfAuctionTest] fail at field=[taskGenerateService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 21 more
Caused by: org.nutz.ioc.IocException: IocBean[taskGenerateService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 23 more
Caused by: java.lang.RuntimeException: IocBean[taskGenerateService] fail at field=[quartzManager]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 26 more
Caused by: org.nutz.ioc.IocException: IocBean[quartzManager] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 28 more
Caused by: java.lang.RuntimeException: IocBean[quartzManager] fail at field=[scheduler]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 31 more
Caused by: org.nutz.ioc.IocException: IocBean[scheduler] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 33 more
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'org.quartz.impl.StdSchedulerFactory'
 by args: []
 because:org.quartz.SchedulerException: ConnectionProvider class 'org.nutz.integration.quartz.NutConnectionProvider' props could not be configured. [See nested exception: java.lang.NullPointerException]
	at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:20)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
	... 36 more
Caused by: org.quartz.SchedulerException: ConnectionProvider class 'org.nutz.integration.quartz.NutConnectionProvider' props could not be configured. [See nested exception: java.lang.NullPointerException]
	at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:936)
	at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1525)
	at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:1541)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:17)
	... 38 more
Caused by: java.lang.NullPointerException
	at org.nutz.integration.quartz.NutConnectionProvider.initialize(NutConnectionProvider.java:30)
	at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:934)
	... 45 more

这是测试用例中调用quartz时,没有装载到装载

我试着吧quartz.properties 放置到test文件夹下,也没有解决问题

谢谢大神,静态块好使,解决了第一个问题。

贴一下testcase类看看,感觉是初始化顺序的问题

quartz插件是最新的版本吗?

还有个办法,test下的quartz.properties把持久化的配置去掉

把持久化的东西去掉就好啦 谢谢
他不是Bean未加载吗 我的想法是怎样把Bean加载到IOC中,你是怎么想到不让他持久化的呢

NutConnectionProvider是获取数据库连接的类

我只保留了

#==============================================================    
#Configure Main Scheduler Properties    
#==============================================================     

==============================================================

Configure ThreadPool

==============================================================

其他都注释啦

添加回复
请先登陆
回到顶部