JUnit是编写性能测试的正确工具吗? [英] Is JUnit the right tool to write performance tests?

查看:233
本文介绍了JUnit是编写性能测试的正确工具吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上周,我创建了两个课程,我的团队对他们的表现表示了一些担忧。为了评估我的代码,我编写了一些简单的JUnit测试,它们通过构建丰富的测试数据集来运行这些类,然后通过相关方法为数千次迭代提供数据。我记录了每次迭代的运行时间,然后使用循环和 System.nanoTime()记录了高,低和平均时间。最后我让JUnit断言高和平均时间都在可接受的范围内。这种测试方法让我的团队对这段代码充满信心。

In the last week I've created two classes which my team expressed some concerns about in regards to their performance. To evaluate my code I wrote some simple JUnit tests which exercised these classes by building rich sets of test data, then feeding that data through the relevant methods for thousands of iterations. I recorded the runtime of each iteration then logged out the high, low, and average times by using loops and System.nanoTime(). Finally I had JUnit assert that the high and average times were within acceptable limits. This testing approach gave my team confidence in this code.

JUnit是否是以这种方式测试性能的合适工具?是否有更好的工具来测试单元(方法和类)级别的性能?

Is JUnit the right tool to test performance in this way? Are there better tools to test performance at the unit (method and class) level?

推荐答案

可能有更好的方法,但那里也是一些有助于使用JUnit实现基准测试的框架。一些有用的实践是热身运行,统计评估。请查看 JUnitBenchmarks JUnitPerf

There may be better approaches, but there are also some frameworks that help implement benchmarking with JUnit. Some useful practices are warmup runs, statistical evaluations. Take a look at JUnitBenchmarks and JUnitPerf

编辑看起来JUnitBenchmarks已被弃用,因为问题已经陈述。该项目的维护人员建议继续 JMH 。谢谢Barry NL的单挑。

EDIT looks like JUnitBenchmarks has been deprecated since the question has been stated. The project's maintainers recommend moving on to JMH. Thank you, Barry NL for the heads-up.

这篇关于JUnit是编写性能测试的正确工具吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆