用p-unit作为你的unit test和performance test工具!

zhanghuangzhu 2007-06-02 05:14:49
或许我们已经习惯了使用JUnit来写单元测试来保证代码质量(我也一直这么做),但可能经常碰到这样子的问题:
1. 我的程序多线程下正确性如何?性能如何?
2. 虽然java有垃圾收集机制,但是两个不同的java程序员实现相同功能的java程序可能使用的内存大不同。

这两点,很难通过JUnit来解决保证。p-unit很好的解决了这两个问题:
1. 同一个测试案例,可以单线程运行,也可以多线程运行。和JUnit不同,p-unit的思想是测试案例就是测试案例,不牵涉运行逻辑,所以同一个测试案例,可以被不同的运行器运行。p-unit测试案例无需实现任何接口,所以当然兼容JUnit Test案例,包括setUp/tearDown函数。

2. 每个测试函数,p-unit给出了运行时间和内存消耗情况,这使得跑单元测试的同时,也做了时间/内存的性能测试,而无需到出现性能瓶颈时使用昂贵的profiler工具来查找问题。

另外,p-unit尤其侧重性能的测试,它支持同一个测试案例,在不同参数下的运行。相信有性能测试经验的程序员都知道,同一个测试场景,往往要测试3-4个数量级的不同数据,看起性能是线性还是几何增长。这对性能评估非常重要。

测试结果方面,p-unit非常灵活,默认的形势有控制台输出,文件输出,图片和pdf报表。当已正确性测试为主的时候,可以选择控制台输出,当以性能测试为主的话,强烈建议图片和pdf输出,非常直观的看出每个测试案例所消耗的时间和内存情况。

p-unit甚至支持不同虚拟机之间的性能比较,其结果反映到同一张图上,对比非常明显。随着java的开源,现在虚拟机的选择也越来越多, SUN, BEA, IBM, Apache Harmony, Kaffe 哪一个虚拟机最适合你的程序,p-unit非常容易告诉你答案。

p-unit官方主页: http://p-unit.sourceforge.net/
p-unit的相关文章:
http://blog.csdn.net/zhanghuangzhu/
http://zhanghuangzhu.blogspot.com/search/label/p-unit


欢迎使用p-unit,大家一起来讨论!
...全文
200 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
About CloudTest License CloudTest is an open source project initiated by the individual, which is distributed on Apatche Licenses 2.0 releases. Every organization or individual is fully granted for viewing its source code or modify the source codes to match his/her own special needs; commercial applications have the greatest license under Apatche Licenses 2.0, More detailed specific Licenses see http://www.apache.org/licenses/ CloudTest is free software, which is distributed in the hope that it will be useful not only for the development founder but also for all individuals and organizations who is in need. Key Values Maybe you are also looking for a new testing framework can help do following: Generate all test cases automatically in one second with test data. It can test all methods including public protected, as well as private Automation regression is also build in framework None java coding jobs for test case development You can test you cases in every where and without time and geographical restrictions By mail By your mobile phone The only thing you need is internet  CloudTest is a redefined unit testing approach and methodology, which can make your testing jobs become much more easy and efficient. It is a pure java lightweight framework integrated test cases management. Test data management, assert management, automation regression, performance monitor and test report in one.  High performance  None java code  Assert support inside  Generate test case and data automatically  Distributed and remote supported  All methods are testable, including public, protected and private  Cloud oriented services, including email and web service and so on  Hot deployment supported  Automatical regression and report supported  Performance monitor and loading testing supported  Spring supported  Transaction management supported  Plugin architecture designed, which is extensible and customized as needed Obtaining Release Package https://sourceforge.net/projects/cloudtest/
This book will teach the concepts of test driven development in Java so you can build clean, maintainable and robust code About This Book Explore the most popular TDD tools and frameworks and become more proficient in building applications Create applications with better code design, fewer bugs, and higher test coverage, enabling you to get them to market quickly Implement test-driven programming methods into your development workflows Who This Book Is For If you're an experienced Java developer and want to implement more effective methods of programming systems and applications, then this book is for you. What You Will Learn Explore the tools and frameworks required for effective TDD development Perform the Red-Green-Refactor process efficiently, the pillar around which all other TDD procedures are based Master effective unit testing in isolation from the rest of your code Design simple and easily maintainable code by implementing different techniques Use mocking frameworks and techniques to easily write and quickly execute tests Develop an application to implement behavior-driven development in conjunction with unit testing Enable and disable features using feature toggles In Detail Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasizes writing a test before writing the necessary code, and then refactoring the code to optimize it.The value of performing TDD with Java, one of the longest established programming languages, is to improve the productivity of programmers and the maintainability and performance of code, and develop a deeper understanding of the language and how to employ it effectively. Starting with the basics of TDD and understanding why its adoption is beneficial, this book will take you from the first steps of TDD with Java until you are confident enough to embrace the practice in your day-to-day routine.You'll be guided through setting up tools, frameworks, and the environment you need,
Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasises writing a test before writing the necessary code, and then refactoring the code to optimize it. The value of performing TDD with Java, one of the most established programming languages, is to improve the productivity of programmers, the maintainability and performance of code, and develop a deeper understanding of the language and how to employ it effectively. Starting with the basics of TDD and reasons why its adoption is beneficial, this book will take you from the first steps of TDD with Java until you are confident enough to embrace the practice in your day-to-day routine. You’ll be guided through setting up tools, frameworks, and the environment you need, and will dive right in to hands-on exercises with the goal of mastering one practice, tool, or framework at a time. You’ll learn about the Red-Green-Refactor procedure, how to write unit tests, and how to use them as executable documentation. With this book you’ll also discover how to design simple and easily maintainable code, work with mocks, utilise behaviour-driven development, refactor old legacy code, and release a half-finished feature to production with feature toggles. You will finish this book with a deep understanding of the test-driven development methodology and the confidence to apply it to application programming with Java. What You Will Learn Explore the tools and frameworks required for effective TDD development Perform the Red-Green-Refactor process efficiently, the pillar around which all other TDD procedures are based Master effective unit testing in isolation from the rest of your code Design simple and easily maintainable codes by implementing different techniques Use mocking frameworks and techniques to easily write and quickly execute tests Develop an application to implement behaviour-driven development in conjunction with unit testing Enable and disable features using Feature Toggles

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧