NutzCN Logo
问答 如果测试类带@IocBean的话,那么mainMoudle的@IocBy的args={}也得把这个测试类的包的路径家在里边吗
发布于 2614天前 作者 qq_4945a577 2672 次浏览 复制 上一个帖子 下一个帖子
标签:
@RunWith(MyNutTestRunner.class)
@IocBean // 必须有
public class SimpleTest extends Assert {
    
 
35 回复

取决于MyNutTestRunner了,仔细看它的超类

下边这个有讲解吗

 protected Ioc createIoc() {
        Ioc ioc = super.createIoc();
        PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
        conf.put("db.url", "jdbc:h2:~/test");
        return ioc;
    }

整个类看完

PropertiesProxy这个类是这么写吗

 protected Ioc createIoc() {
        Ioc ioc = super.createIoc();
        PropertiesProxy conf = ioc.get(PropertiesProxy.class, "org.test.tongyong");
        conf.put("db.url", "jdbc:mysql://127.0.0.1:3306/wcc");
        conf.put("db.username", "root");
        conf.put("db.password", "root");
        conf.put("db.maxActive", "100");
        conf.put("db.testWhileIdle", "true");
        conf.put("db.filters", "mergeStat");
        conf.put("db.connectionProperties", "druid.stat.slowSqlMillis=2000");
        return ioc;
    }
org.nutz.ioc.IocException: IocBean[org.test.tongyong] For object [org.test.tongyong] - type:[class org.nutz.ioc.impl.PropertiesProxy]

	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.test.tongyong.TestRunner.createIoc(TestRunner.java:23)
	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.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: org.nutz.ioc.ObjectLoadException: Object 'org.test.tongyong' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 15 more


你还是改@IocBy吧

给个模板行不,源码量太多了

if (log.isDebugEnabled()) {
            log.debugf("Get '%s'<%s>", new Object[]{name, type == null ? "" : type});
        }

        try {
            if (this.mirrors instanceof LifeCycle) {
                ((LifeCycle)this.mirrors).init();
            }
        } catch (Exception var16) {
            throw new IocException("_mirror_factory_init", var16, "Mirror Factory init fail", new Object[0]);
        }

        IocMaking ing = this.makeIocMaking(context, name);
        IocContext cntx = ing.getContext();
        ObjectProxy op = cntx.fetch(name);
        Object var7;
        if (null == op) {
            var7 = this.lock_get;
            synchronized(this.lock_get) {
                op = cntx.fetch(name);
                if (null == op) {
                    try {
                        if (log.isDebugEnabled()) {
                            log.debug("\t >> Load definition name=" + name);
                        }

                        IocObject iobj = this.loader.load(this.createLoading(), name);
                        if (null == iobj) {
                            String[] var9 = this.loader.getName();
                            int var10 = var9.length;

                            for(int var11 = 0; var11 < var10; ++var11) {
                                String iocBeanName = var9[var11];
                                if (3 > LevenshteinDistance.computeLevenshteinDistance(name.toLowerCase(), iocBeanName.toLowerCase())) {
                                    throw new IocException(name, "Undefined object '%s' but found similar name '%s'", new Object[]{name, iocBeanName});
                                }
                            }
    protected Class<?> getMainModule() {
        return MainModule.class;
    }
   //protected Ioc createIoc() {
   //     Ioc ioc = super.createIoc();
   //     PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
   //     conf.put("db.url", "jdbc:h2:~/test");
   //     return ioc;
   // }

然后确保MainModule的@IocBy设置能覆盖testcase所在的package

我iocBy能设置 ,我就是想学习一下掉的那部分应该怎么配置

配置什么??

我看nutz关于junit的支持那个http://nutzam.com/core/testing/junit_testing.html;想用这个来做测试,但是怎么也跑不通

当前报什么错误

package org.test;

import org.junit.runners.model.InitializationError;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.mock.NutTestRunner;
import org.visual.tongyong.MainModule;

public class TestRunner extends NutTestRunner {
    public TestRunner(Class<?> klass) throws InitializationError {
        super(klass);
    }

    public Class<?> getMainModule() {
        return MainModule.class;
    }

    /**
     * 可覆盖createIoc,实现参数覆盖, bean替换,等定制.
     */
    protected Ioc createIoc() {
        Ioc ioc = super.createIoc();
        PropertiesProxy conf = ioc.get(PropertiesProxy.class, "org");
        conf.put("db.url", "jdbc:mysql://127.0.0.1:3306/wcc");
        return ioc;
    }
}
package org.test;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.nutz.dao.Dao;
import org.nutz.dao.SqlManager;
import org.nutz.dao.Sqls;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.visual.tongyong.bean.WccProvinceQueryView;

import java.util.ArrayList;
import java.util.List;

@RunWith(TestRunner.class)
@IocBean
public class test extends Assert {

    private static final Log log = Logs.get();
    //Logger log = Logger.getLogger(test.class);

    @Inject("refer:$ioc")
    protected Ioc ioc;

    @Inject
    protected Dao dao;
    @Test
    public void test_t() {
        List<WccProvinceQueryView> list = new ArrayList<>();
            SqlManager sqlm = new FileSqlManager("sqls/");
            Sql sql = sqlm.create("WarningData.query2");
        Sql sql2= Sqls.create("SELECT count(*) FROM test");
        sql2.setCallback(Sqls.callback.ints());
        dao.execute(sql2);
        int i = sql2.getInt();
        log.info(list.size()+1);
    }
}
D:\Software_Develops\JDK\bin\java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53520,suspend=y,server=n -ea -Didea.test.cyclic.buffer.size=1048576 -Dfile.encoding=UTF-8 -classpath "D:\Software_Develops\IntelliJ IDEA 2017.1\lib\idea_rt.jar;D:\Software_Develops\IntelliJ IDEA 2017.1\plugins\junit\lib\junit-rt.jar;D:\Software_Develops\IntelliJ IDEA 2017.1\plugins\junit\lib\junit5-rt.jar;D:\Software_Develops\JDK\jre\lib\charsets.jar;D:\Software_Develops\JDK\jre\lib\deploy.jar;D:\Software_Develops\JDK\jre\lib\ext\access-bridge-64.jar;D:\Software_Develops\JDK\jre\lib\ext\cldrdata.jar;D:\Software_Develops\JDK\jre\lib\ext\dnsns.jar;D:\Software_Develops\JDK\jre\lib\ext\jaccess.jar;D:\Software_Develops\JDK\jre\lib\ext\jfxrt.jar;D:\Software_Develops\JDK\jre\lib\ext\localedata.jar;D:\Software_Develops\JDK\jre\lib\ext\nashorn.jar;D:\Software_Develops\JDK\jre\lib\ext\sunec.jar;D:\Software_Develops\JDK\jre\lib\ext\sunjce_provider.jar;D:\Software_Develops\JDK\jre\lib\ext\sunmscapi.jar;D:\Software_Develops\JDK\jre\lib\ext\sunpkcs11.jar;D:\Software_Develops\JDK\jre\lib\ext\zipfs.jar;D:\Software_Develops\JDK\jre\lib\javaws.jar;D:\Software_Develops\JDK\jre\lib\jce.jar;D:\Software_Develops\JDK\jre\lib\jfr.jar;D:\Software_Develops\JDK\jre\lib\jfxswt.jar;D:\Software_Develops\JDK\jre\lib\jsse.jar;D:\Software_Develops\JDK\jre\lib\management-agent.jar;D:\Software_Develops\JDK\jre\lib\plugin.jar;D:\Software_Develops\JDK\jre\lib\resources.jar;D:\Software_Develops\JDK\jre\lib\rt.jar;E:\Work\InstelliJIDEAR_WorkSpaceNo.1\visualdisplay\target\test-classes;E:\Work\InstelliJIDEAR_WorkSpaceNo.1\visualdisplay\target\classes;D:\Software_Develops\maven\Repository\org\nutz\nutz\1.r.63-SNAPSHOT\nutz-1.r.63-20170926.144244-97.jar;D:\Software_Develops\maven\Repository\org\apache\shiro\shiro-core\1.3.2\shiro-core-1.3.2.jar;D:\Software_Develops\maven\Repository\org\apache\shiro\shiro-web\1.3.2\shiro-web-1.3.2.jar;D:\Software_Develops\maven\Repository\org\apache\shiro\shiro-ehcache\1.3.2\shiro-ehcache-1.3.2.jar;D:\Software_Develops\maven\Repository\net\sf\ehcache\ehcache-core\2.5.3\ehcache-core-2.5.3.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-plugins-daocache\1.r.62\nutz-plugins-daocache-1.r.62.jar;D:\Software_Develops\maven\Repository\net\sf\ehcache\ehcache\2.10.4\ehcache-2.10.4.jar;D:\Software_Develops\maven\Repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\Software_Develops\maven\Repository\org\slf4j\slf4j-log4j12\1.7.25\slf4j-log4j12-1.7.25.jar;D:\Software_Develops\maven\Repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;D:\Software_Develops\maven\Repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\Software_Develops\maven\Repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\Software_Develops\maven\Repository\jstl\jstl\1.2\jstl-1.2.jar;D:\Software_Develops\maven\Repository\org\apache\commons\commons-email\1.5\commons-email-1.5.jar;D:\Software_Develops\maven\Repository\com\sun\mail\javax.mail\1.5.6\javax.mail-1.5.6.jar;D:\Software_Develops\maven\Repository\javax\mail\mail\1.4\mail-1.4.jar;D:\Software_Develops\maven\Repository\javax\activation\activation\1.1\activation-1.1.jar;D:\Software_Develops\maven\Repository\cn\apiclub\tool\simplecaptcha\1.2.2\simplecaptcha-1.2.2.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-integration-quartz\1.r.62\nutz-integration-quartz-1.r.62.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-integration-shiro\1.r.62\nutz-integration-shiro-1.r.62.jar;D:\Software_Develops\maven\Repository\org\slf4j\jcl-over-slf4j\1.7.24\jcl-over-slf4j-1.7.24.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-plugins-apidoc\1.r.62\nutz-plugins-apidoc-1.r.62.jar;D:\Software_Develops\maven\Repository\redis\clients\jedis\2.8.1\jedis-2.8.1.jar;D:\Software_Develops\maven\Repository\org\apache\commons\commons-pool2\2.4.2\commons-pool2-2.4.2.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-integration-jedis\1.r.63-SNAPSHOT\nutz-integration-jedis-1.r.63-20170925.052238-96.jar;D:\Software_Develops\maven\Repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\Software_Develops\maven\Repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\Software_Develops\maven\Repository\org\apache\maven\plugins\maven-resources-plugin\2.4.3\maven-resources-plugin-2.4.3.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-plugin-api\2.0.6\maven-plugin-api-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-project\2.0.6\maven-project-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-profile\2.0.6\maven-profile-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-artifact-manager\2.0.6\maven-artifact-manager-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-plugin-registry\2.0.6\maven-plugin-registry-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-core\2.0.6\maven-core-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-file\1.0-beta-2\wagon-file-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-plugin-parameter-documenter\2.0.6\maven-plugin-parameter-documenter-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-http-lightweight\1.0-beta-2\wagon-http-lightweight-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-http-shared\1.0-beta-2\wagon-http-shared-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\jtidy\jtidy\4aug2000r7-dev\jtidy-4aug2000r7-dev.jar;D:\Software_Develops\maven\Repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\reporting\maven-reporting-api\2.0.6\maven-reporting-api-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\doxia\doxia-sink-api\1.0-alpha-7\doxia-sink-api-1.0-alpha-7.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-provider-api\1.0-beta-2\wagon-provider-api-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-repository-metadata\2.0.6\maven-repository-metadata-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-error-diagnostics\2.0.6\maven-error-diagnostics-2.0.6.jar;D:\Software_Develops\maven\Repository\commons-cli\commons-cli\1.0\commons-cli-1.0.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-ssh-external\1.0-beta-2\wagon-ssh-external-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-ssh-common\1.0-beta-2\wagon-ssh-common-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-plugin-descriptor\2.0.6\maven-plugin-descriptor-2.0.6.jar;D:\Software_Develops\maven\Repository\org\codehaus\plexus\plexus-interactivity-api\1.0-alpha-4\plexus-interactivity-api-1.0-alpha-4.jar;D:\Software_Develops\maven\Repository\org\apache\maven\wagon\wagon-ssh\1.0-beta-2\wagon-ssh-1.0-beta-2.jar;D:\Software_Develops\maven\Repository\com\jcraft\jsch\0.1.27\jsch-0.1.27.jar;D:\Software_Develops\maven\Repository\classworlds\classworlds\1.1\classworlds-1.1.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-artifact\2.0.6\maven-artifact-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-settings\2.0.6\maven-settings-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-model\2.0.6\maven-model-2.0.6.jar;D:\Software_Develops\maven\Repository\org\apache\maven\maven-monitor\2.0.6\maven-monitor-2.0.6.jar;D:\Software_Develops\maven\Repository\org\codehaus\plexus\plexus-container-default\1.0-alpha-9-stable-1\plexus-container-default-1.0-alpha-9-stable-1.jar;D:\Software_Develops\maven\Repository\org\codehaus\plexus\plexus-utils\2.0.5\plexus-utils-2.0.5.jar;D:\Software_Develops\maven\Repository\org\apache\maven\shared\maven-filtering\1.0-beta-4\maven-filtering-1.0-beta-4.jar;D:\Software_Develops\maven\Repository\org\sonatype\plexus\plexus-build-api\0.0.4\plexus-build-api-0.0.4.jar;D:\Software_Develops\maven\Repository\org\codehaus\plexus\plexus-interpolation\1.13\plexus-interpolation-1.13.jar;D:\Software_Develops\maven\Repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar;D:\Software_Develops\maven\Repository\org\quartz-scheduler\quartz\2.2.1\quartz-2.2.1.jar;D:\Software_Develops\maven\Repository\c3p0\c3p0\0.9.1.1\c3p0-0.9.1.1.jar;D:\Software_Develops\maven\Repository\org\quartz-scheduler\quartz-jobs\2.2.1\quartz-jobs-2.2.1.jar;D:\Software_Develops\maven\Repository\com\alibaba\druid\1.0.27\druid-1.0.27.jar;D:\Software_Develops\JDK\lib\jconsole.jar;D:\Software_Develops\JDK\lib\tools.jar;D:\Software_Develops\maven\Repository\org\nutz\nutz-plugins-mock\1.r.63-SNAPSHOT\nutz-plugins-mock-1.r.63-20170925.052309-96.jar;D:\Software_Develops\maven\Repository\junit\junit\4.12\junit-4.12.jar;D:\Software_Develops\maven\Repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\Software_Develops\maven\Repository\org\mockito\mockito-core\2.10.0\mockito-core-2.10.0.jar;D:\Software_Develops\maven\Repository\net\bytebuddy\byte-buddy\1.7.4\byte-buddy-1.7.4.jar;D:\Software_Develops\maven\Repository\net\bytebuddy\byte-buddy-agent\1.7.4\byte-buddy-agent-1.7.4.jar;D:\Software_Develops\maven\Repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 org.test.test,test_t
Connected to the target VM, address: '127.0.0.1:53520', transport: 'socket'

Test ignored.
2017-09-27 14:43:48,472 org.nutz.resource.Scans.printLocations(Scans.java:527) DEBUG - Locations count=105 time use 292ms
2017-09-27 14:43:48,491 org.nutz.resource.Scans.scan(Scans.java:280) DEBUG - Found 4 resource by src( ioc/ ) , regex( ^(.+[.])(js|json)$ )
2017-09-27 14:43:48,492 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) DEBUG - loading [dao.js]
2017-09-27 14:43:48,498 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) DEBUG - loading [ehcache.js]
2017-09-27 14:43:48,498 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) DEBUG - loading [mail.js]
2017-09-27 14:43:48,499 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) DEBUG - loading [dao.js]
2017-09-27 14:43:48,501 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:57) DEBUG - Loaded 8 bean define from path=[ioc/] --> [dao, cacheProvider, emailAuthenticator, htmlEmail, cacheExecutor, conf, dataSource, cacheManager]
2017-09-27 14:43:48,537 org.nutz.resource.Scans.scan(Scans.java:280) DEBUG - Found 27 resource by src( org/visual/tongyong/ ) , regex( ^.+[.]class$ )
2017-09-27 14:43:48,591 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.module.AuthorityModule
2017-09-27 14:43:48,614 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.module.CaptchaModule
2017-09-27 14:43:48,619 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.module.DataModule
2017-09-27 14:43:48,623 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.module.UserModule
2017-09-27 14:43:48,636 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.module.UserProfileModule
2017-09-27 14:43:48,642 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.quartz.job.CleanNonActiveUserJob
2017-09-27 14:43:48,648 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.service.AuthorityServiceImpl
2017-09-27 14:43:48,650 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.service.EmailServiceImpl
2017-09-27 14:43:48,656 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:76) DEBUG - Found @IocBean : class org.visual.tongyong.service.UserService
2017-09-27 14:43:48,741 org.nutz.castor.Castors.reload(Castors.java:115) DEBUG - Using 95 castor for Castors
2017-09-27 14:43:48,745 org.nutz.ioc.loader.annotation.AnnotationIocLoader.<init>(AnnotationIocLoader.java:52) INFO  - Found 9 classes in 1 base-packages!
beans = ["cleanNonActiveUserJob", "authorityService", "userProfileModule", "dataModule", "captchaModule", "authorityModule", "userModule", "emailService", "userService"]
2017-09-27 14:43:48,757 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:40) DEBUG - Loaded 5 bean define from reader --
[txREPEATABLE_READ, txSERIALIZABLE, txNONE, txREAD_UNCOMMITTED, txREAD_COMMITTED]
2017-09-27 14:43:48,761 org.nutz.ioc.loader.combo.ComboIocLoader.createIocLoader(ComboIocLoader.java:110) DEBUG - found jedis -- org.nutz.integration.jedis.JedisIocLoader
2017-09-27 14:43:48,770 org.nutz.resource.Scans.scan(Scans.java:280) DEBUG - Found 1 resource by src( org/nutz/integration/jedis/jedis.js ) , regex( ^(.+[.])(js|json)$ )
2017-09-27 14:43:48,770 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:49) DEBUG - loading [org/nutz/integration/jedis/jedis.js]
2017-09-27 14:43:48,773 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:57) DEBUG - Loaded 9 bean define from path=[org/nutz/integration/jedis/jedis.js] --> [redisService, jedisCluster, jedisClusterNodes, jedisClusterWrapper, pubSubService, jedisPoolConfig, jedisPool, jedisAgent, redis]
2017-09-27 14:43:48,793 org.nutz.ioc.loader.combo.ComboIocLoader.createIocLoader(ComboIocLoader.java:110) DEBUG - found quartz -- org.nutz.integration.quartz.QuartzIocLoader
2017-09-27 14:43:48,801 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:57) DEBUG - Loaded 0 bean define from path=[] --> []
2017-09-27 14:43:48,817 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:98) INFO  - NutIoc init begin ...
2017-09-27 14:43:48,823 org.nutz.ioc.impl.NutIoc.<init>(NutIoc.java:115) INFO  - ... NutIoc init complete
2017-09-27 14:43:48,824 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'org'<class org.nutz.ioc.impl.PropertiesProxy>
2017-09-27 14:43:48,833 org.nutz.ioc.aop.SimpleAopMaker.<init>(SimpleAopMaker.java:79) DEBUG - Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
2017-09-27 14:43:48,836 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=org

org.nutz.ioc.IocException: IocBean[org] For object [org] - type:[class org.nutz.ioc.impl.PropertiesProxy]

	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.test.TestRunner.createIoc(TestRunner.java:23)
	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.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: org.nutz.ioc.ObjectLoadException: Object 'org' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 15 more

Disconnected from the target VM, address: '127.0.0.1:53520', transport: 'socket'

Process finished with exit code -1

 PropertiesProxy conf = ioc.get(PropertiesProxy.class, "org"); // 不是org, 是 conf

这个是maven项目没有 “conf”的目录

conf不是目录名称, 是dao.js里面的名字叫conf的ioc bean

 protected Ioc createIoc() {
        Ioc ioc = super.createIoc();
        PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
        conf.put("db.url", "jdbc:mysql://127.0.0.1:3306/wcc");
        return ioc;
    }
package org.test;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.nutz.dao.Dao;
import org.nutz.dao.SqlManager;
import org.nutz.dao.Sqls;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.visual.tongyong.bean.WccProvinceQueryView;

import java.util.ArrayList;
import java.util.List;

@RunWith(TestRunner.class)
@IocBean
public class test extends Assert {

    private static final Log log = Logs.get();
    //Logger log = Logger.getLogger(test.class);

    @Inject("refer:$ioc")
    protected Ioc ioc;

    @Inject
    protected Dao dao;
    @Test
    public void test_t() {
        List<WccProvinceQueryView> list = new ArrayList<>();
            SqlManager sqlm = new FileSqlManager("sqls/");
            Sql sql = sqlm.create("WarningData.query2");
        Sql sql2= Sqls.create("SELECT count(*) FROM test");
        sql2.setCallback(Sqls.callback.ints());
        dao.execute(sql2);
        int i = sql2.getInt();
        log.info(list.size()+1);
    }
}
2017-09-27 14:50:15,558 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'test'<class org.test.test>
2017-09-27 14:50:15,558 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=test

org.nutz.ioc.IocException: IocBean[test] For object [test] - type:[class org.test.test]

	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
	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: org.nutz.ioc.ObjectLoadException: Object 'test' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:166)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 20 more

2017-09-27 14:50:15,573 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:255) INFO  - org.nutz.ioc.impl.NutIoc@2076287037 is closing. startup date [17-09-27 14:50:15.442]
2017-09-27 14:50:15,573 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) DEBUG - Depose object 'conf' ...
2017-09-27 14:50:15,574 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:262) INFO  - org.nutz.ioc.impl.NutIoc@2076287037 is deposed. startup date [17-09-27 14:50:15.442]

Process finished with exit code -1

我在项目建了两个资源目录,一个是resource 一个是 TestResource ,兽总我是不是建多了,一个resources就够了

@IocBy没有涵盖org.test这个package?? 而且这package和类名也太随意的吧,自己给自己挖坑.

maven下 src/test/resources 就是放test的资源文件的

通了,不过有两个疑惑,1:PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");这个您刚才说conf是dao.js里的ioc bean,我这个项目里有两个dao.js(一个在Java目录下的resources的ioc/下,一个在test的resources的ioc下),这里ioc.get(PropertiesProxy.class, "conf");它找的是哪个dao.js里的

@IocBy(type=ComboIocProvider.class, args={
        "*js", "ioc/",
        "*anno", "org.visual.tongyong","org.mytest",
        "*tx",
        "*jedis",
        "*quartz"})

第二个不太懂的地方是mainModule里的IocBy()里配置上测试包的路径后,mvn compile或mvn install 执行的时候会不会把测试代码也带上一起编译到war包里了

你可以覆盖getIocArgs方法嘛

给个模板把...

添加Runner. web项目建议覆盖getMainModule方法, 非web项目覆盖getIocArgs

因为这里提到的这两个方法的作用有点似懂非懂,能看明白点但是不知道怎么写,应该是我没有完全理解这个类,汗...

一般来说, test类的package应该是 org.xxx.yyy.test, 这样就不需要改ioc配置

覆盖getIocArgs方法后是不是就不用在mainMoudle的IocBy里加入test类的package包路径了

是的, 那几个方法一个套一个的

你用的不是maven?? NutTestRunner 的源码没几行啊

如果用第一个方式(修改IocBy的方式)maven打包的时候会把测试代码也打在war包里面吗?

不会的, test代码不会打包进war

那就用第一个方式就是最简单的了如果有特殊测试情况(需要连接另一个服务器专门的用来测试的数据库的时候)就覆盖getIocArgs方法来改变resource的扫描路径(改成test下的TestResources下的ioc上)。以后这样的方案来搭项目行吗?

test下的TestResources是神马东西?? maven的结构里没有这种目录

我一直用的Intellij IDEA 它的结构中有 Resources,Test Resources

我在网上找到了一段话

他们两个有不同的输出路径,跑test时候test的路径优先级比较高,在testresources的classpath找到就不去resources的classpath找了。反之,跑正常程序找resources的文件,所以如果都有log4j的配置文件,跑test的会使用testresources的配置文件,直接跑src下的程序会使用resources下的配置文件。
”

是不是我问的问题跟nutz没有关系了,两个resources是idear的目录特殊结构

src/test/resources 它的文字里面少了反斜杠而已

反正跟nutz也没有关系了,PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");选择哪个资源是maven的优先级决定的,是吧?

在网上找的

src/main/java:里面的java文件只能直接加载src/main/resources下的资源,不能直接加载src/test/resources下的资源;
src/test/java: 里面的java文件既能加载src/test/resources下的资源,又能加载src/main/resources下的资源,当两个resources下都有要加载的同名资源时候,优先选择src/test/java下的资源;
添加回复
请先登陆
回到顶部