how to test a file output whether it is successfully written or not?

624 views
Skip to first unread message

VK

unread,
Feb 5, 2020, 7:31:38 AM2/5/20
to Google C++ Testing Framework
when we test a program we normally test whether return values is correct or not(numbers or strings) using EXPECT_EQ.
Is there any way to check whether a file is successfully written or not using google test?
one way is to read the file and compare it with content before writing...
is there any other efficient ways to do testing 

Josh Kelley

unread,
Feb 5, 2020, 8:17:15 PM2/5/20
to VK, Google C++ Testing Framework
You have two basic options. The first option, asyou said, is to read the actual file and compare its contents, or call filesystem APIs and verify that their results match with EXPECT_EQ, and so on. (And there are techniques you can use to speed that up, such as writing to a tmpfs on Linux.) The second option is to modify your system under test to use an interface for writing files, instead of directly calling the OS file APIs itself. In production, you can use an implementation of this interface that does actual file writes, while the tests use a mock that validates that the expected interface calls occur but skips the actual file operations for performance. For more information on this second approach, you can read up on Google Mock or other mocking implementations.

-- 
Josh Kelley

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googletestframework/0f180886-4e8f-4744-bb12-1f874a653f24%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages