??xml version="1.0" encoding="utf-8" standalone="yes"?>91精品国产综合久久久久,精品国内二区三区,亚洲视频一起http://www.aygfsteel.com/aspirin/category/9106.htmlJAVA_HOMEzh-cnTue, 19 Jun 2007 09:16:45 GMTTue, 19 Jun 2007 09:16:45 GMT60mysql事务http://www.aygfsteel.com/aspirin/archive/2007/06/18/124946.htmlaspirinaspirinMon, 18 Jun 2007 07:03:00 GMThttp://www.aygfsteel.com/aspirin/archive/2007/06/18/124946.htmlhttp://www.aygfsteel.com/aspirin/comments/124946.htmlhttp://www.aygfsteel.com/aspirin/archive/2007/06/18/124946.html#Feedback0http://www.aygfsteel.com/aspirin/comments/commentRss/124946.htmlhttp://www.aygfsteel.com/aspirin/services/trackbacks/124946.html但发C个很奇怪的问题Qhibernate的事务无法会滚,q个问题困扰我好几天Q今天终于解决了Q原来mysql有配|有问题。mysqld?U存储方式,MyISAM 是默认存储方式,但是不支持事务,所以导致了我的问题Q只要把默认讄?code class="literal">default-storage-engine=innodb可以了Q当然也可以在每个table创徏的时候指定?br />希望对碰到此c问题的朋友有所帮助?br />

aspirin 2007-06-18 15:03 发表评论
]]>
初探Quartz的扩?/title><link>http://www.aygfsteel.com/aspirin/archive/2006/05/19/47034.html</link><dc:creator>aspirin</dc:creator><author>aspirin</author><pubDate>Fri, 19 May 2006 04:49:00 GMT</pubDate><guid>http://www.aygfsteel.com/aspirin/archive/2006/05/19/47034.html</guid><wfw:comment>http://www.aygfsteel.com/aspirin/comments/47034.html</wfw:comment><comments>http://www.aygfsteel.com/aspirin/archive/2006/05/19/47034.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aspirin/comments/commentRss/47034.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aspirin/services/trackbacks/47034.html</trackback:ping><description><![CDATA[    Quartz作ؓ一个开源的作业调度框架Q已l广泛应用于j2ee中。因为项目需要一个Q务管理模块,所以选择了Quartzq个强大的框Ӟq对其进? 了扩展以适应目的要求。首先介l一下我们的pȝ构架Q采用webworkQspringQhibernate整合架构Q我的Q务是无缝的把Quartz 加入到系l,提供一个界面,提供一些操作,使最l用戯够自己定义在什么时间对什么东西做哪些事情Q“哪些事情”是预先定义的,提供l客户选择Q这是客? 需求,pȝ地要求是能够Ҏ的扩展,对增加一个新的Q务定义提供一些简单的接口。这里不对Quartz作介l了Q想了解的h参考官方网站:http: //www.opensymphony.com/quartz/Q由于涉及的东西比较多,有些l节带q了Q我大致的介绍一下M的设计?br />     作业调度框架Q主要要解决的问题是在某个时间对某些对象作某些动作?br />     对于某个旉QQuarta提供一个字W表辑ּ来表C,q方面要做的是提供一个方便的界面Q直观的对其q行讄Q不能让最l客L那些对客h意义的字W? 丌Ӏ这个工作需要解析那些字W,做v来还是有Ҏ思的Q也是比较麻烦的Q有兴趣的话可以自己去试试?br />     对于某些对象作和某些动作QQuartz都交l程序员自己d义,它提供一个Job接口,Ҏ们来说增加Q务是比较单的一件事?既然Quartz提供 q么单的接口,我ؓ什么还要对其进行扩展呢?q就要来?某些对象"?在一般的pȝ?某个动作"所操纵的对象是固定?比如定期删除日至,定期? 库存{?׃pȝ地特D?我们"某个动作"对哪些对象是不确定的,"哪些对象"由我提供一个界?由最l客户去军_对一个或多个对象q行操作.<br />     q样引入了一个范围的概念,"某个动作"是作用在一定范围内?q个范围׃仅仅是哪些对象了,也可能是旉范围,比如删除几天前的日志信息.到这里对 d的定义有所改变?一个Q务包括一些范围也可以说是条g,q个条g不包括触发点q个条g),一个动?所以系l中定义了一个IRange接口,范围? 表示都保存在一个XML字符?XML字符串的l构和怎么解析都交l具体的子对?q样q了子cȝ灉|?<br /> public interface IRange {<br />     public Map saveToMap(String strMap);//保存范围参数<br />     public List getResult(Map map);//解析范围参数,q返回操作对象线E列?br />     public List getViewInfo();取得面表示方式,l合了webwork<br /> }<br /> 一个Q务对应一个IRange的子c?IRange的子cdd的各U参数范?动作q行了实?接着q加入一个IRangeManager接口,<br /> public interface IRangeManager {<br />     public void saveDataMap(Long jobId, String strMap)throws SchedulerException;//保存范围参数<br />     public List getObjects(Map map);//取得对象列表,其中包括了对参数的解?br />     public List getViews(Map map);<br /> }<br />     实现的功能是对范围进行管?包括对Quartz的操?主要一些保存数据库{的操作,q样对于增加一个新的Range子类可以不用知道Quartz?<br />     q样因ؓ很多东西都是可配|的,增加了灵zL?对以后Q务的d定义了一些接?考虑C扩展?在设计这个模块的时?ȝ思\是把那些不变的东襉K装h,把能变得东西都交l具体的d?<br /> 上面我只是大致讲了一?׃水^有限,可能讲的不是清楚,比较?我没有提供具体的例子,只是提供了一个思\,希望对大家有所帮助,或者你q有更好的设?请与我联p?<br /><br /><img src ="http://www.aygfsteel.com/aspirin/aggbug/47034.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aspirin/" target="_blank">aspirin</a> 2006-05-19 12:49 <a href="http://www.aygfsteel.com/aspirin/archive/2006/05/19/47034.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Quartz与Hibernate在数据库的连接方面的l合http://www.aygfsteel.com/aspirin/archive/2006/05/19/47033.htmlaspirinaspirinFri, 19 May 2006 04:47:00 GMThttp://www.aygfsteel.com/aspirin/archive/2006/05/19/47033.htmlhttp://www.aygfsteel.com/aspirin/comments/47033.htmlhttp://www.aygfsteel.com/aspirin/archive/2006/05/19/47033.html#Feedback0http://www.aygfsteel.com/aspirin/comments/commentRss/47033.htmlhttp://www.aygfsteel.com/aspirin/services/trackbacks/47033.html 先谈谈Quartz,我用的版本是1.5.1,后面的版本我没去看了,没时?接下来说的都以这个版本ؓ?Quartz虽然在提供一? ConnectionProvider接口,提供l程序扩?但是看它的StdSchedulerFactory实现c?要对它进行扩展还是一件比较麻? 一件事?所以我q接修改了StdSchedulerFactoryc?以达到的我的需?
接下来的问题是既然要l合,那么让Quartz来提供连接池配置呢还是有Hibernate提供.研究了两者的q接池方面的源代?发现 Hibernate的连接池设计q远好于Quartz,Quartz目前只提供一个连接池提供cPoolingConnectionProvider,? 且用的q接池是dbcp,q个q接池听说问题多?相反hibernate提供了更加灵zȝ配置,所以连接池由Hibernate提供.
    首先实现一个Quartz中ConnectionProvider子类HibernateConnectionProvider
public class HibernateConnectionProvider implements ConnectionProvider {
    private Connection con = null;
    protected static ThreadLocal hibernateHolder = new ThreadLocal();
    public Connection getConnection() throws SQLException {
        con = null;
        SessionFactoryImpl sessionFactory = null;
        sessionFactory = (SessionFactoryImpl) Global.getSessionFacotry();
        con = sessionFactory.getConnectionProvider().getConnection();
    return con;
}
public void shutdown() throws SQLException {
    // FIXME Auto-generated method stub
}
}
,然后修改StdSchedulerFactory,在不破坏其本来的逻辑和可配置性下q行了相应的修改.修改的是private Scheduler instantiate() throws SchedulerExceptionҎ,扑ֈ//Set up any DataSourcesD进行修?代码如下:
String[] dsNames = cfg.getPropertyGroups(PROP_DATASOURCE_PREFIX);
        for (int i = 0; i < dsNames.length; i++) {
            PropertiesParser pp = new PropertiesParser(cfg.getPropertyGroup(
                    PROP_DATASOURCE_PREFIX + "." + dsNames[i], true));

            String dsDriver = pp
                    .getStringProperty(PROP_DATASOURCE_DRIVER, null);
            String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null);
            boolean dsAlwaysLookup = pp.getBooleanProperty(
                    PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false);
            String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, "");
            String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, "");
            int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 3);
            String providerClass = pp.getStringProperty(
                    PROP_DATASOURCE_PROVIDER_CLASS, null);
            String dsJndi = pp
                    .getStringProperty(PROP_DATASOURCE_JNDI_URL, null);
            String dsJndiInitial = pp.getStringProperty(
                    PROP_DATASOURCE_JNDI_INITIAL, null);
            String dsJndiProvider = pp.getStringProperty(
                    PROP_DATASOURCE_JNDI_PROVDER, null);
            String dsJndiPrincipal = pp.getStringProperty(
                    PROP_DATASOURCE_JNDI_PRINCIPAL, null);
            String dsJndiCredentials = pp.getStringProperty(
                    PROP_DATASOURCE_JNDI_CREDENTIALS, null);
            String dsValidation = pp.getStringProperty(
                    PROP_DATASOURCE_VALIDATION_QUERY, null);
            if (providerClass == null
                    || providerClass.equals("")
                    || providerClass
                            .equals("org.quartz.utils.PoolingConnectionProvider")) {
                if (dsDriver == null) {
                    initException = new SchedulerException(
                            "Driver not specified for DataSource: "
                                    + dsNames[i]);
                    throw initException;
                }
                if (dsURL == null) {
                    initException = new SchedulerException(
                            "DB URL not specified for DataSource: "
                                    + dsNames[i]);
                    throw initException;
                }
                try {
                    PoolingConnectionProvider cp = new PoolingConnectionProvider(
                            dsDriver, dsURL, dsUser, dsPass, dsCnt,
                            dsValidation);
                    dbMgr = DBConnectionManager.getInstance();
                    dbMgr.addConnectionProvider(dsNames[i], cp);
                } catch (SQLException sqle) {
                    initException = new SchedulerException(
                            "Could not initialize DataSource: " + dsNames[i],
                            sqle);
                    throw initException;
                }
            } else if (providerClass
                    .equals("org.quartz.utils.JNDIConnectionProvider")) {
                Properties props = null;
                if (null != dsJndiInitial || null != dsJndiProvider
                        || null != dsJndiPrincipal || null != dsJndiCredentials) {
                    props = new Properties();
                    if (dsJndiInitial != null)
                        props.put(PROP_DATASOURCE_JNDI_INITIAL, dsJndiInitial);
                    if (dsJndiProvider != null)
                        props.put(PROP_DATASOURCE_JNDI_PROVDER, dsJndiProvider);
                    if (dsJndiPrincipal != null)
                        props.put(PROP_DATASOURCE_JNDI_PRINCIPAL,
                                dsJndiPrincipal);
                    if (dsJndiCredentials != null)
                        props.put(PROP_DATASOURCE_JNDI_CREDENTIALS,
                                dsJndiCredentials);
                }
                JNDIConnectionProvider cp = new JNDIConnectionProvider(dsJndi,
                        props, dsAlwaysLookup);
                dbMgr = DBConnectionManager.getInstance();
                dbMgr.addConnectionProvider(dsNames[i], cp);
            } else if (providerClass
                    .equals("org.quartz.utils.HibernateConnectionProvider")) {
                HibernateConnectionProvider cp = new HibernateConnectionProvider();
                dbMgr = DBConnectionManager.getInstance();
                dbMgr.addConnectionProvider(dsNames[i], cp);
            } else {
                initException = new SchedulerException(
                        "Provider_Class not Supported: " + providerClass);
                throw initException;
            }

        }
    最后就是修攚w|文件quartz.properties,加入
#org.quartz.dataSource.myDS.provider_class = org.quartz.utils.JNDIConnectionProvider
#org.quartz.dataSource.myDS.provider_class = org.quartz.utils.PoolingConnectionProvider
org.quartz.dataSource.myDS.provider_class = org.quartz.utils.HibernateConnectionProvider?的供参?
    l过试,需要对hibernateq接池的一些参数进行微?q样完成了Quartz与Hibernate在数据库的连接方面的l合,如果有更好的解决Ҏ,误pL.



aspirin 2006-05-19 12:47 发表评论
]]>
log的作?/title><link>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37904.html</link><dc:creator>aspirin</dc:creator><author>aspirin</author><pubDate>Tue, 28 Mar 2006 14:26:00 GMT</pubDate><guid>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37904.html</guid><wfw:comment>http://www.aygfsteel.com/aspirin/comments/37904.html</wfw:comment><comments>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37904.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aspirin/comments/commentRss/37904.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aspirin/services/trackbacks/37904.html</trackback:ping><description><![CDATA[        最q同事在到一个棘手的问题,用了一天还是调试不出到底哪里出错了,郁闷中时老大q来p了一个很好的解决Ҏ,用日志跟t?没过半小?问题找C,定位很准?q让我看到日志的重要性了.<br />        一开始我q是写一些log?但是那时候觉得好像没什么必?后来׃来没有写q?因ؓ我想不出他的好处.现在在知道日志真正的作用,而且也是一个很强大 的工?qx在写代码的时?׃几秒钟写个log,也许会觉得很?但是我觉得还是值得?<br />        q也是一个习惯的问题,好的E序员之所以是个好的程序员是因Z有好的习?q些好的习惯带来的好处也是很多的.写日志只是其中一个好习惯,我也要慢慢留意一些好的习?慢慢ȝ.<img src ="http://www.aygfsteel.com/aspirin/aggbug/37904.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aspirin/" target="_blank">aspirin</a> 2006-03-28 22:26 <a href="http://www.aygfsteel.com/aspirin/archive/2006/03/28/37904.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Quartz的入门资?/title><link>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37902.html</link><dc:creator>aspirin</dc:creator><author>aspirin</author><pubDate>Tue, 28 Mar 2006 14:24:00 GMT</pubDate><guid>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37902.html</guid><wfw:comment>http://www.aygfsteel.com/aspirin/comments/37902.html</wfw:comment><comments>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37902.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aspirin/comments/commentRss/37902.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aspirin/services/trackbacks/37902.html</trackback:ping><description><![CDATA[        Quartz作ؓ一个开源的作业调度框架Q已l广泛应用于j2ee中,在这里提供一些资料以供参考:<br />        首先是官方网站:<a >http://www.opensymphony.com/quartz/</a> q里可以下蝲源代码,q有论坛Qjira{最原始的资料。 ?    <br />        一个写的不错的介绍Quartz的中文文章:<a ><b>详细讲解Quartz如何从入门到_N?/b></a>Q英文不好的可以参考这个。这文章大致的讲了Quartz的框Ӟ很多l节q没有涉及,q也难怪,一文章不可能都写上去的?br />        如果你想l箋了解QuartzQ官方网站有面向开发h员的文档Q但是放在不L的角落,我以前闲逛时扑ֈQ现在一时找不到Q什么时候什么找C在加上去Q我? 另外地方扑ֈ其中的几章,q两章是其中最重要的两章,可以作ؓ参考,http://javaforge.com/proj/doc.do?doc_id= 1740<br />        如果你还要l深入研IӞp自己到cvsM载最新源码,自己研读了,大家成功,我会接下d一些自׃中学到的东西?img src ="http://www.aygfsteel.com/aspirin/aggbug/37902.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aspirin/" target="_blank">aspirin</a> 2006-03-28 22:24 <a href="http://www.aygfsteel.com/aspirin/archive/2006/03/28/37902.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FC4下JDBC应该注意的问?/title><link>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37901.html</link><dc:creator>aspirin</dc:creator><author>aspirin</author><pubDate>Tue, 28 Mar 2006 14:22:00 GMT</pubDate><guid>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37901.html</guid><wfw:comment>http://www.aygfsteel.com/aspirin/comments/37901.html</wfw:comment><comments>http://www.aygfsteel.com/aspirin/archive/2006/03/28/37901.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aspirin/comments/commentRss/37901.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aspirin/services/trackbacks/37901.html</trackback:ping><description><![CDATA[ <p>在完全刚装好的fc4上用jdbcq行数据库操作出C一下错误:<br /><!--StartFragment --> java.net.SocketException: Invalid argument or cannot assign requested address<br />at java.net.PlainSocketImpl.socketConnect(Native Method)<br />at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)<br />at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)<br />at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)<br />at java.net.Socket.connect(Socket.java:452)<br />at java.net.Socket.connect(Socket.java:402)<br />at java.net.Socket.<init>(Socket.java:309)<br />at java.net.Socket.<init>(Socket.java:124) <br /><!--StartFragment -->       q是IP地址的问?在FC4中默认的是IPv6 socket,JDK1.4支持的应该是IPv4,具体原因可以查看SUN公司l出的解?<br />解决办法是在q行JAVAE序时加?-Djava.net.preferIPv4Stack=true ?<br /><br />java -Djava.net.preferIPv4Stack=true application. </p> <p>但是q个在每ơ都要加上这句话Q另有解x法是<!--StartFragment --> 修改 /etc/modprobe.conf 文g,增加 <br /><br />alias net-pf-10 off<br />alias ipv6 off<br /><br />q样׃用增加参?"-Djava.net.preferIPv4Stack=true ",重v卛_. </p> <p>但是既要ipv6又能解决q个问题的方法还没找到。希望高人指?/p> <img src ="http://www.aygfsteel.com/aspirin/aggbug/37901.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aspirin/" target="_blank">aspirin</a> 2006-03-28 22:22 <a href="http://www.aygfsteel.com/aspirin/archive/2006/03/28/37901.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>junit with ant(转蝲)http://www.aygfsteel.com/aspirin/archive/2006/03/28/37900.htmlaspirinaspirinTue, 28 Mar 2006 14:18:00 GMThttp://www.aygfsteel.com/aspirin/archive/2006/03/28/37900.htmlhttp://www.aygfsteel.com/aspirin/comments/37900.htmlhttp://www.aygfsteel.com/aspirin/archive/2006/03/28/37900.html#Feedback0http://www.aygfsteel.com/aspirin/comments/commentRss/37900.htmlhttp://www.aygfsteel.com/aspirin/services/trackbacks/37900.html 附:最q在弄ccQ也找了一些ant资料Q顺便{载记录一?/font>

转自http://ant.apache.org/manual/OptionalTasks/junit.html

JUnit

Description

This task runs tests from the JUnit testing framework. The latest version of the framework can be found at http://www.junit.org. This task has been tested with JUnit 3.0 up to JUnit 3.8.1; it won't work with versions prior to JUnit 3.0.

Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.

Note: You must have junit.jar and the class files for the <junit> task in the same classpath. You can do one of:

  1. Put both junit.jar and the optional tasks jar file in ANT_HOME/lib.
  2. Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
  3. Do neither of the above, and instead, specify their locations using a <classpath> element in the build file. See the FAQ for details.

Tests are defined by nested test or batchtest tags (see nested elements).

Parameters

Attribute Description Required
printsummary Print one-line statistics for each testcase. Can take the values on, off, and withOutAndErr. withOutAndErr is the same as on but also includes the output of the test as written to System.out and System.err. No; default is off.
fork Run the tests in a separate VM. No; default is off.
forkmode Controls how many Java Virtual Machines get created if you want to fork some tests. Possible values are "perTest" (the default), "perBatch" and "once". "once" creates only a single Java VM for all tests while "perTest" creates a new VM for each TestCase class. "perBatch" creates a VM for each nested <batchtest> and one collecting all nested <test>s. Note that only tests with the same settings of filtertrace, haltonerror, haltonfailure, errorproperty and failureproperty can share a VM, so even if you set forkmode to "once", Ant may have to create more than a single Java VM. This attribute is ignored for tests that don't get forked into a new Java VM. since Ant 1.6.2 No; default is perTest.
haltonerror Stop the build process if an error occurs during the test run. No; default is off.
errorproperty The name of a property to set in the event of an error. No
haltonfailure Stop the build process if a test fails (errors are considered failures as well). No; default is off.
failureproperty The name of a property to set in the event of a failure (errors are considered failures as well). No.
filtertrace Filter out Junit and Ant stack frames from error and failure stack traces. No; default is on.
timeout Cancel the individual tests if they don't finish in the given time (measured in milliseconds). Ignored if fork is disabled. No
maxmemory Maximum amount of memory to allocate to the forked VM. Ignored if fork is disabled. No
jvm The command used to invoke the Java Virtual Machine, default is 'java'. The command is resolved by java.lang.Runtime.exec(). Ignored if fork is disabled. No; default is java.
dir The directory in which to invoke the VM. Ignored if fork is disabled. No
newenvironment Do not propagate the old environment when new environment variables are specified. Ignored if fork is disabled. No; default is false.
includeantruntime Implicitly add the Ant classes required to run the tests and JUnit to the classpath in forked mode. Note: Please read the Ant FAQ if you want to set this to false and use the XML formatter at the same time. No; default is true.
showoutput Send any output generated by tests to Ant's logging system as well as to the formatters. By default only the formatters receive the output. No
tempdir Where Ant should place temporary files. Since Ant 1.6. No; default is the project's base directory.
reloading Whether or not a new classloader should be instantiated for each test case.
Ignore if fork is set to true. Since Ant 1.6.
No; default is true.

By using the errorproperty and failureproperty attributes, it is possible to perform setup work (such as starting an external server), execute the test, clean up, and still fail the build in the event of a failure.

The filtertrace attribute condenses error and failure stack traces before reporting them. It works with both the plain and XML formatters. It filters out any lines that begin with the following string patterns:

   "junit.framework.TestCase"
"junit.framework.TestResult"
"junit.framework.TestSuite"
"junit.framework.Assert."
"junit.swingui.TestRunner"
"junit.awtui.TestRunner"
"junit.textui.TestRunner"
"java.lang.reflect.Method.invoke("
"sun.reflect."
"org.apache.tools.ant."

Nested Elements

The <junit> task supports a nested <classpath> element that represents a PATH like structure.

jvmarg

If fork is enabled, additional parameters may be passed to the new VM via nested <jvmarg> elements. For example:

<junit fork="yes">
<jvmarg value="/-Djava.compiler=NONE"/>
...
</junit>

would run the test in a VM without JIT.

<jvmarg> allows all attributes described in Command-line Arguments.

sysproperty

Use nested <sysproperty> elements to specify system properties required by the class. These properties will be made available to the VM during the execution of the test (either ANT's VM or the forked VM, if fork is enabled). The attributes for this element are the same as for environment variables.

<junit fork="no">
<sysproperty key="basedir" value="${basedir}"/>
...
</junit>

would run the test in ANT's VM and make the basedir property available to the test.

syspropertyset

You can specify a set of properties to be used as system properties with syspropertysets.

since Ant 1.6.

env

It is possible to specify environment variables to pass to the forked VM via nested <env> elements. For a description of the <env> element's attributes, see the description in the exec task.

Settings will be ignored if fork is disabled.

bootclasspath

The location of bootstrap class files can be specified using this PATH like structure - will be ignored if fork is not true or the target VM doesn't support it (i.e. Java 1.1).

since Ant 1.6.

permissions

Security permissions can be revoked and granted during the execution of the class via a nested permissions element. For more information please see permissions

Settings will be ignored if fork is enabled.

since Ant 1.6.

assertions

You can control enablement of Java 1.4 assertions with an <assertions> subelement.

Assertion statements are currently ignored in non-forked mode.

since Ant 1.6.

formatter

The results of the tests can be printed in different formats. Output will always be sent to a file, unless you set the usefile attribute to false. The name of the file is determined by the name of the test and can be set by the outfile attribute of <test>.

There are three predefined formatters - one prints the test results in XML format, the other emits plain text. The formatter named brief will only print detailed information for testcases that failed, while plain gives a little statistics line for all test cases. Custom formatters that need to implement org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter can be specified.

If you use the XML formatter, it may not include the same output that your tests have written as some characters are illegal in XML documents and will be dropped.

Note: Please read the Ant FAQ if you want to set the fork attribute to true, the includeAntRuntime attribute to false and use the XML formatter at the same time.

Attribute Description Required
type Use a predefined formatter (either xml, plain, or brief). Exactly one of these.
classname Name of a custom formatter class.
extension Extension to append to the output filename. Yes, if classname has been used.
usefile Boolean that determines whether output should be sent to a file. No; default is true.
if Only use formatter if the named property is set. No; default is true.
unless Only use formatter if the named property is not set. No; default is true.

test

Defines a single test class.

Attribute Description Required
name Name of the test class. Yes
fork Run the tests in a separate VM. Overrides value set in <junit>. No
haltonerror Stop the build process if an error occurs during the test run. Overrides value set in <junit>. No
errorproperty The name of a property to set in the event of an error. Overrides value set in <junit>. No
haltonfailure Stop the build process if a test fails (errors are considered failures as well). Overrides value set in <junit>. No
failureproperty The name of a property to set in the event of a failure (errors are considered failures as well). Overrides value set in <junit>. No
filtertrace Filter out Junit and Ant stack frames from error and failure stack traces. Overrides value set in <junit>. No; default is on.
todir Directory to write the reports to. No; default is the current directory.
outfile Base name of the test result. The full filename is determined by this attribute and the extension of formatter. No; default is TEST-name, where name is the name of the test specified in the name attribute.
if Only run test if the named property is set. No
unless Only run test if the named property is not set. No

Tests can define their own formatters via nested <formatter> elements.

batchtest

Define a number of tests based on pattern matching.

batchtest collects the included files from any number of nested <fileset>s. It then generates a test class name for each file that ends in .java or .class.

Attribute Description Required
fork Run the tests in a separate VM. Overrides value set in <junit>. No
haltonerror Stop the build process if an error occurs during the test run. Overrides value set in <junit>. No
errorproperty The name of a property to set in the event of an error. Overrides value set in <junit>. No
haltonfailure Stop the build process if a test fails (errors are considered failures as well). Overrides value set in <junit>. No
failureproperty The name of a property to set in the event of a failure (errors are considered failures as well). Overrides value set in <junit> No
filtertrace Filter out Junit and Ant stack frames from error and failure stack traces. Overrides value set in <junit>. No; default is on.
todir Directory to write the reports to. No; default is the current directory.
if Only run tests if the named property is set. No
unless Only run tests if the named property is not set. No

Batchtests can define their own formatters via nested <formatter> elements.

Examples

<junit>
<test name="my.test.TestCase"/>
</junit>

Runs the test defined in my.test.TestCase in the same VM. No output will be generated unless the test fails.

<junit printsummary="yes" fork="yes" haltonfailure="yes">
<formatter type="plain"/>
<test name="my.test.TestCase"/>
</junit>

Runs the test defined in my.test.TestCase in a separate VM. At the end of the test, a one-line summary will be printed. A detailed report of the test can be found in TEST-my.test.TestCase.txt. The build process will be stopped if the test fails.

<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${java.class.path}"/>
</classpath>

<formatter type="plain"/>

<test name="my.test.TestCase" haltonfailure="no" outfile="result">
<formatter type="xml"/>
</test>

<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>

Runs my.test.TestCase in the same VM, ignoring the given CLASSPATH; only a warning is printed if this test fails. In addition to the plain text test results, for this test a XML result will be output to result.xml. Then, for each matching file in the directory defined for ${src.tests} a test is run in a separate VM. If a test fails, the build process is aborted. Results are collected in files named TEST-name.txt and written to ${reports.tests}.



aspirin 2006-03-28 22:18 发表评论
]]>
վ֩ģ壺 | | Ž| | | | ʲ| ̨| ʤ| ʲ| ̩| | | ѽ| | ϸ| ӯ| | ڰ| | ƽȪ| | | | | ŷ| ɽ| | | | | | Ӣ| ̨| ׷| Ϫ| ̨| | ĵ| | |