Xzajo's Weblog

All | Java | nbxdoclet | NetBeans | Personal | Project Extensions | Sun | Testing
« NBXdoclet cooperates... | Main | NBXdoclet met annota... »
20060414 Friday April 14, 2006

The best documentation of API - unit test

Developers don't like writing of documentation. Many tutorials and documentations are obsolete. I saw wrong javadoc comments sometimes. I claim that the best documentation of API are the unit tests.

For example I was reading javadoc of Java Language Model API (JMI). From the javadoc I didn't get knowledge how to read, create and modify annotations. Thanks to Google I found some unit tests of JMI module which uses annotations. I can use a pattern shown bellow in my code and I'm sure that it is good usage.

 public void testAddAnnotation() throws java.io.IOException, FileStateInvalidException {
        boolean fail = true;
        Utility.beginTrans(true);
        try {
            Method method = (Method) clazz.getContents().get(0);
            // log the annotation information
            getLog().println("Method '" + method.getName() + "' has following annotations:");
            for (Iterator it = method.getAnnotations().iterator(); it.hasNext(); ) {
                Annotation annotation = (Annotation) it.next();
                getLog().println("\tAnnotation named '" + annotation.getType().getName() + "'.");
                for (Iterator it2 = annotation.getAttributeValues().iterator(); it2.hasNext(); ) {
                    AttributeValue attribute = (AttributeValue) it2.next();
                    getLog().println("\t\tAttribute value '" + attribute.getName() + "', '" + ((MetadataElement) attribute.getValue()).getSourceText() + "'.");
                }
            }
            Annotation ann = createSimpleAnn("\"2004-06-21\"", "\"Lojza\"", "\"Unknown\"", "46");
            method = (Method) clazz.getContents().get(1);
            method.getAnnotations().add(ann);
            fail = false;
       }
        finally {
            Utility.endTrans(fail);
        }
        assertFile("File is not correctly generated.",
            Utility.getFile(getDataDir(), "org/netbeans/test/codegen/AnnotationClass.java"),
            getGoldenFile("testAddAnnotation_AnnotationClass.pass"),
            getWorkDir()
        );
    }

I got a idea. Why not to add link to unit tests to javadoc html. TestNG uses annotations to specify tests groups. Why to not add annotations which package, class or method is tested. The link to test sources should be added to javadoc documentation. The test can be also indexed. Usage statistics can shown in javadoc. After that many developers, who don't write tests, will have to write tests I hope. Because the API users (developers) rather choose already tested API.

Posted by xzajo ( Apr 14 2006, 11:14:10 AM CEST ) Permalink Comments [19]

Comments:

i love you Xzajo marry me and be the father of my children

Posted by bill gates on April 14, 2006 at 11:26 AM CEST #

As long as Agile and Testdriven development and have the hype this works fine, now it is cool to write unit-tests, but it hat been cool to write nice javadoc-comments, too. Test have the big advantages that you (have to) refactor them, so this kind of doc cannot possibly be outdated

Posted by Carsten on April 14, 2006 at 01:27 PM CEST #

Yes it will be cool to write nice javadoc-comments. But to have it up to date is not realistic. There are too many classes methods and dependencies between different API's and fields that to maintain consistency in javadoc is difficult. The test tells you how to use it.

Posted by xzajo on April 14, 2006 at 02:57 PM CEST #

气枪 仿真枪 猎头 猎头公司

Posted by 传奇私服 on April 11, 2007 at 08:21 AM CEST #

猎头顾问 广州猎头 上海猎头 北京猎头

Posted by 传奇私服 on April 11, 2007 at 08:22 AM CEST #

猎头公司 发电机 发电机组 发电机出租

Posted by 传奇私服 on April 11, 2007 at 08:22 AM CEST #

发电设备 发电机租赁 租赁发电机 康明斯

Posted by 传奇私服 on April 11, 2007 at 08:22 AM CEST #

出租发电机 空气过滤器 4d影院 动感影院

Posted by 传奇私服 on April 11, 2007 at 08:22 AM CEST #

厨房设备 油烟净化器 安全工程师 造价工程师

Posted by 传奇私服 on April 11, 2007 at 08:23 AM CEST #

房地产估价师 进销存软件 进销存 erp软件

Posted by 传奇私服 on April 11, 2007 at 08:23 AM CEST #

生产管理软件 风柜 北京婚庆 北京婚庆公司

Posted by 传奇私服 on April 11, 2007 at 08:23 AM CEST #

瑜伽 北京瑜伽 瑜伽教练培训 肚皮舞

Posted by 传奇私服 on April 11, 2007 at 08:24 AM CEST #

肚皮舞培训 鱼鳞病

Posted by 传奇私服 on April 11, 2007 at 08:24 AM CEST #

a href="http://www.bjzdsw.com/show.shtml">不锈钢水箱 防雷 防雷器 职业装

Posted by 传奇私服 on April 11, 2007 at 08:25 AM CEST #

wow power leveling wow power leveling wow powerleveling wow powerleveling 搬家公司

Posted by 水无痕 on July 21, 2007 at 05:14 AM CEST #

The best of luck! Best wishes! Best regards!
http://www.bjseek.com.cn
http://www.bjxlzx.cn
http://www.sense.com.cn
http://jglsx.blog.sohu.com/
http://blog.china.alibaba.com/blog/jglsx.html
http://jglsx.blog.hexun.com/
http://tw.netsh.com/eden/blog/ctl_eden_blog.php?iBlogID=2610970
http://tw.netsh.com/eden/blog/ctl_eden_blog.php?iBlogID=2632783
http://blog.soufun.com/blog_12178456.html
http://blog.china-pub.com/blog.asp?name=jlb148140960
http://www.phpchina.com/38743
http://hexun.com/jglsx/default.html
http://www.xiongcaocao.com/?sid=116
http://jlb999.blog.163.com/
http://jjllbb.eomoo.com/user18/jlb148140960/index.shtml
http://hexun.com/xicao1/default.html
http://hexun.com/xicao3/default.html
http://hexun.com/xicao6/default.html
http://hexun.com/xicao9/default.html
http://hexun.com/xicao2/default.html
http://hexun.com/xicao7/default.html
http://hexun.com/xicao4/default.html
http://hexun.com/xicao5/default.html
http://hexun.com/xicao8/default.html
http://hexun.com/zwwsl/default.html
http://xicao6.blog.hexun.com/
http://xicao7.blog.hexun.com/
http://xicao8.blog.hexun.com/
http://xicao9.blog.hexun.com/
http://zwwsl.blog.hexun.com/
http://xicao1.blog.hexun.com/
http://xicao2.blog.hexun.com/
http://xicao3.blog.hexun.com/
http://xicao4.blog.hexun.com
http://xicao5.blog.hexun.com
http://tzgoogle.blog.hexun.com
http://hexun.com/tzgoogle/default.html
http://blog.ccidnet.com/blog-htm-uid-71265.html
http://hexun.com/baom/default.html
http://baom.blog.hexun.com
http://www.0576w.cn/
http://www.0576w.cn/catalog.asp?cate=1
http://www.0576w.cn/catalog.asp?cate=2
http://www.0576w.cn/catalog.asp?cate=3
http://www.0576w.cn/catalog.asp?cate=5
http://www.0576w.cn/catalog.asp?cate=6
http://www.0576w.cn/post/google.html

Posted by 数据恢复 on February 14, 2008 at 01:46 AM CET #

[url=http://baom.photo.hexun.com/]幸福快乐的女人[/url]

Posted by 数据恢复 on February 14, 2008 at 01:47 AM CET #

http://www.wowgolds.co.uk wow gold http://www.wowgolds.co.uk cheap wow gold http://www.wowgolds.co.uk buy wow gold http://www.wowgolds.co.uk world of warcraft gold http://www.wowgolds.co.uk wow http://www.wowgolds.co.uk world of warcraft http://www.wowgolds.co.uk/wow-gold.html wow gold http://www.wowgolds.co.uk/warrior.html WoW Warrior http://www.wowgolds.co.uk/hunter.html WoW Hunter http://www.wowgolds.co.uk/rogue.html WoW Rogue http://www.wowgolds.co.uk/paladin.html WoW Paladin http://www.wowgolds.co.uk/shaman.html WoW Shaman http://www.wowgolds.co.uk/priest.html WoW Priest http://www.wowgolds.co.uk/mage.html WoW Mage http://www.wowgolds.co.uk/druid.html WoW Druid http://www.wowgolds.co.uk/warlock.html WoW Warlock http://www.powerleveling2.cn power leveling http://www.powerleveling2.cn powerleveling http://www.wowpowerleveling2.cn wow power leveling http://www.wowpowerleveling2.cn wow powerleveling http://www.wowpro.cn wow guides http://www.wowmmo.cn wow tips http://ggtop.nbatop.com google排名 http://ggtop.nbatop.com google左侧排名 http://ggtop.nbatop.com google排名服务 http://www.baidupaiming.net 百度推广 http://www.baidupaiming.net 百度排名 http://www.fzqsnet.cn 网站推广 http://www.thebiz8.com 商业吧 http://www.thebiz8.com/jichuang.html 机床 http://www.thebiz8.com/leddeng.html LED灯 http://www.thebiz8.com/dianchi.html 电池 http://www.thebiz8.com/suliao.html 塑料 http://www.thebiz8.com/shexiangji.html 摄像机 http://www.thebiz8.com/yimin.html 移民 http://www.thebiz8.com/jiachun.html 甲醇 http://www.thebiz8.com/ranliao.html 染料 http://www.0591qs.cn 福州热线 http://www.sportblog.org.cn 体育博客 http://www.stockblog.org.cn 股票博客 http://www.gameblog.org.cn 游戏博客 http://www.cheap-wow-gold.org.cn 魔兽博客 http://www.excamtest.cn 考试博客 http://www.carblog.org.cn 汽车博客 http://www.houseblog.org.cn 房产博客 http://www.pcblog.org.cn 电脑博客 http://powerlin518.iblog.com powerlin518 http://www.xcelwebdesign.com logo design http://www.xcelwebdesign.com website design http://www.xcelwebdesign.com web design http://www.shangbiaodesign.cn 商标设计

Posted by power leveling on March 20, 2008 at 04:12 PM CET #

http://sunnyren.weblog.com
this blog introduces jewelry products and fashion jewelry.

Posted by fashion jewelry on October 31, 2008 at 06:12 AM CET #

Post a Comment:

Comments are closed for this entry.

Calendar

RSS Feeds

Search

Links

Navigation

Referers