Junit:拆分集成测试和单元测试 [英] Junit: splitting integration test and Unit tests

查看:125
本文介绍了Junit:拆分集成测试和单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了Junit测试的负载,但是这些测试(除了大多数无法使用的测试)是实际单元测试和集成测试(需要外部系统,数据库等)的混合.

I've inherited a load of Junit test, but these tests (apart from most not working) are a mixture of actual unit test and integration tests (requiring external systems, db etc).

因此,我正在尝试一种将它们实际分离出来的方法,这样我就可以快速好地运行单元测试,然后再运行集成测试.

So I'm trying to think of a way to actually separate them out, so that I can run the unit test nice and quickly and the integration tests after that.

选项是..

  1. 将它们拆分到单独的目录中.

  1. Split them into separate directories.

从v3版本移至Junit4,并注释类以将它们分开.

Move to Junit4 (from v3) and annotate the classes to separate them.

使用文件命名约定来告诉类是什么,即AdapterATest和 AdapterAIntergrationTest.

Use a file naming convention to tell what a class is , i.e. AdapterATest and AdapterAIntergrationTest.

3的问题是Eclipse可以选择运行所选项目/程序包或文件夹中的所有测试".因此,仅运行集成测试将非常困难.

3 has the issue that Eclipse has the option to "Run all tests in the selected project/package or folder". So it would make it very hard to just run the integration tests.

2:冒着开发人员可能开始在单元测试类中编写集成测试的风险,并且变得一团糟.

2: runs the risk that developers might start writing integration tests in unit test classes and it just gets messy.

1:似乎是最干净的解决方案,但是我的直觉说那里肯定有更好的解决方案.

1: Seems like the neatest solution, but my gut says there must be a better solution out there.

这就是我的问题,您如何将集成测试和适当的单元测试分开?

So that is my question, how do you lot break apart integration tests and proper unit tests?

推荐答案

由于组织政策(和Junit 3的遗留问题),我目前使用单独的目录,但是我现在打算使用Junit 4自己过渡到注释.

I currently use separate directories due to organisational policy (and Junit 3 legacy) but I'm looking to transition to annotations myself now I'm on Junit 4.

对于开发人员将集成测试放在您的单元测试类中,我不会太担心-必要时在您的编码标准中添加一条规则.

I wouldn't be overly concerned about developers putting integration tests in your unit test classes - add a rule in your coding standards if necessary.

我很想知道除了注释或在物理上将类分开之外,还有哪些其他解决方案.

I'm interested to know what sort of other solutions there might be apart from annotations or physically separating the classes..

这篇关于Junit:拆分集成测试和单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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