如何最好地测试Java代码? [英] How to best test Java code?

查看:90
本文介绍了如何最好地测试Java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己一直在研究一个比较大的系统,这是我第一次使用大型系统(同时处理200多个信息渠道)。我知道如何使用Junit测试每个方法,以及如何测试边界条件。但是,对于系统测试,我需要测试所有的接口,也可能是一些压力测试(可能还有其他事情要做,但我不知道它们是什么)。我是测试世界的新手,请给我一些建议或指出一些好的代码测试人员如何进行系统测试。

I have been working on a comparatively large system on my own, and it's my first time working on a large system(dealing with 200+ channels of information simultaneously). I know how to use Junit to test every method, and how to test boundary conditions. But still, for system test, I need to test all the interfacing and probably so some stress test as well (maybe there are other things to do, but I don't know what they are). I am totally new to the world of testing, and please give me some suggestions or point me to some info on how a good code tester would do system testing.

PS:我有两个具体问题:
如何测试私有函数?
如何测试界面并避免副作用?

PS: 2 specific questions I have are: how to test private functions? how to testing interfaces and avoid side effects?

推荐答案

以下是两个可能有用的网站:

Here are two web sites that might help:

第一个是开源的列表Java工具。许多工具都是JUnit的插件,可以在更高的集成级别上进行更简单的测试或测试。

The first is a list of open source Java tools. Many of the tools are addons to JUnit that allow either easier testing or testing at a higher integration level.

根据您的系统,有时JUnit可用于系统测试,但是测试的结构可以不同。

Depending on your system, sometimes JUnit will work for system tests, but the structure of the test can be different.

至于私人方法,请检查这个问题(以及它引用的问题)。

As for private methods, check this question (and the question it references).

你无法测试接口(因为没有行为),但是您可以创建一个抽象基础测试类来测试接口的实现是否遵循其合同。

You cannot test interfaces (as there is no behavior), but you can create an abstract base test classes for testing that implementations of an interface follow its contract.

编辑:此外,如果您还没有单元测试,请查看有效地使用旧版代码;它是测试未能很好地进行测试的代码的必备条件。

Also, if you don't already have unit tests, check out Working Effectivly with Legacy Code; it is a must for testing code that is not set up well for testing.

这篇关于如何最好地测试Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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