本文介绍了不同测试类的通用setUp代码放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有几种不同的测试类,它们要求在运行某些测试之前先创建某些对象.现在,我想知道是否应该将对象初始化代码放入单独的帮助程序类或超类中.

I have several different test classes that require that certain objects are created before those tests can be run. Now I'm wondering if I should put the object initialization code into a separate helper class or superclass.

这样做肯定会减少测试类中重复代码的数量,但也会使它们的可读性降低.

Doing so would surely reduce the amount of duplicate code in my test classes but it would also make them less readable.

是否有指南或模式如何处理单元测试的通用setUp代码?

Is there a guideline or pattern how to deal with common setUp-code for unit tests?

推荐答案

处理测试代码时的模式和实践与您正在测试的代码没有什么不同.测试代码中应包含相同的OO原则和实践,但请注意.如果您采用的方法使单元测试难以找到故障点...您做错了.

Patterns and practices when dealing with test code is no different then the code which you are testing. The same OO principles and practices should exist within your test code, with one caveat. If the approach you take makes the unit test difficult to find the failure point...you are doing it wrong.

这篇关于不同测试类的通用setUp代码放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:43