集成或单元测试?无需访问外部系统即可测试类

时间:2022-09-25 11:50:22

Integration tests depends on external systems such as database or network connection. These components should be mock in unit testig. But when we testing three different classes which behavior depends on each other is this an integretion or unit test? Should that classes be mocked? Lets assume that these classes have no acces to external systems and their behavior is strictly connected.

集成测试取决于外部系统,如数据库或网络连接。这些组件应该在单元testig中模拟。但是,当我们测试三个不同类别的行为相互依赖时,这是一个整合还是单元测试?这些课程应该被嘲笑吗?让我们假设这些类没有访问外部系统,并且它们的行为是严格连接的。

2 个解决方案

#1


2  

As I know.

我所知。

Purposes of both testing are different from each other. https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-842-fundamentals-of-systems-engineering-fall-2015/lecture-notes/MIT16_842F15_Ses9_Ver.pdf

两种测试的目的彼此不同。 https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-842-fundamentals-of-systems-engineering-fall-2015/lecture-notes/MIT16_842F15_Ses9_Ver.pdf

But unit testing may support integration testing; If used unit testing framework supports.

但单元测试可能支持集成测试;如果使用单元测试框架支持。

#2


1  

First of all, the terminology varies from company to company.

首先,术语因公司而异。

According to the book "How Google Tests Software" they call tests "Small Tests", "Medium Tests" and "Large Tests", if I remember correctly. Other companies call it "Whitebox Tests", "Unit Tests", "Integration Tests", "End-to-End Tests". Even though the same name might be used in one company, it could mean something different in another company.

根据“Google如何测试软件”一书,如果我没记错的话,他们会将测试称为“小测试”,“中等测试”和“大测试”。其他公司称之为“白盒测试”,“单元测试”,“集成测试”,“端到端测试”。尽管在一家公司中可能使用相同的名称,但在另一家公司中它可能意味着不同的东西。

Secondly: To mock or not to mock depends on what you want to test. If you want to test the interaction of those 3 classes then I suggest using all three as is, unless: If you want to isolate the behaviour of one class or desire a hard-to-achieve-behaviour/unrealistic behaviour/not-yet-implemented-behaviour or it is hard to use the other classes, I suggest mocking the other classes.

其次:模拟或不模拟取决于你想要测试的内容。如果你想测试这三个类的交互,那么我建议按原样使用这三个类,除非:如果你想要隔离一个类的行为或者想要一个难以实现的行为/不切实际的行为/还没有 - 实现行为或很难使用其他类,我建议嘲笑其他类。

#1


2  

As I know.

我所知。

Purposes of both testing are different from each other. https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-842-fundamentals-of-systems-engineering-fall-2015/lecture-notes/MIT16_842F15_Ses9_Ver.pdf

两种测试的目的彼此不同。 https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-842-fundamentals-of-systems-engineering-fall-2015/lecture-notes/MIT16_842F15_Ses9_Ver.pdf

But unit testing may support integration testing; If used unit testing framework supports.

但单元测试可能支持集成测试;如果使用单元测试框架支持。

#2


1  

First of all, the terminology varies from company to company.

首先,术语因公司而异。

According to the book "How Google Tests Software" they call tests "Small Tests", "Medium Tests" and "Large Tests", if I remember correctly. Other companies call it "Whitebox Tests", "Unit Tests", "Integration Tests", "End-to-End Tests". Even though the same name might be used in one company, it could mean something different in another company.

根据“Google如何测试软件”一书,如果我没记错的话,他们会将测试称为“小测试”,“中等测试”和“大测试”。其他公司称之为“白盒测试”,“单元测试”,“集成测试”,“端到端测试”。尽管在一家公司中可能使用相同的名称,但在另一家公司中它可能意味着不同的东西。

Secondly: To mock or not to mock depends on what you want to test. If you want to test the interaction of those 3 classes then I suggest using all three as is, unless: If you want to isolate the behaviour of one class or desire a hard-to-achieve-behaviour/unrealistic behaviour/not-yet-implemented-behaviour or it is hard to use the other classes, I suggest mocking the other classes.

其次:模拟或不模拟取决于你想要测试的内容。如果你想测试这三个类的交互,那么我建议按原样使用这三个类,除非:如果你想要隔离一个类的行为或者想要一个难以实现的行为/不切实际的行为/还没有 - 实现行为或很难使用其他类,我建议嘲笑其他类。