简体   繁体   English

在Google测试框架中从另一个测试执行测试

[英]Executing test from another test in google test framework

Let's say I have two tests in the same testcase: writeTest and readTest 假设我在同一个测试用例中有两个测试:writeTest和readTest

TEST_F(testcase, writeTest)
{
  ASSERT_EQ(OK, write_something();
} 

TEST_F(testcase, readTest)
{
  ASSERT_EQ(OK, write_something();
  ASSERT_EQ(OK, read_something();
}

My question is, can I execute writeTest from readTest? 我的问题是,我可以从readTest执行writeTest吗?

To read something there must be something written. 要阅读某些东西,必须写一些东西。 So I want to execute the writeTest (while being in test code of readTest) rather than repeating the codes of writeTest? 所以我想执行writeTest(同时处于readTest的测试代码中)而不是重复执行writeTest的代码?

This is specially important when there is huge line of code in the writeTest. 当writeTest中有大量代码时,这尤其重要。

Is there a need for your first test case at all. 根本不需要第一个测试用例。 If you write something, how will you know it has worked without reading it afterwards? 如果您编写某些内容,那么以后又不阅读它怎么会知道它是否有效?

First thing you have to ask yourself is, "What is the purpose of my test?" 您必须问自己的第一件事是:“我的考试目的是什么?”

For example. 例如。

Purpose: Write something which should return an error. 目的:写一些应该返回错误的东西。 Now it more important check the return error instead of verifying. 现在,更重要的是检查返回错误而不是进行验证。

Purpose: Write a positive test case Now its important to test that what you have written can also be read. 目的:编写一个肯定的测试用例现在,测试您所写的内容也可以被阅读很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM