Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

19
  • 3
    Edit your question with a minimal reproducible example. In particular we'd need your main. Commented Jan 7, 2023 at 1:55
  • You need to use test macros like ASSERT_* and EXPECT_* to have test conditions evaluated by Google Test. If you do not use them the tests will pass unless an exception is thrown regardless of any error conditions generated by the code you are testing. You should read through more of the documentation starting the primer. For instance ASSERT_TRUE(ifs) or ASSERT_TRUE(ifs.is_open()) Commented Jan 7, 2023 at 2:00
  • 1
    You should learn about what current working directory means. When you open a file without specifying its location (directory), like "input.txt", the current working directory is assumed to be the location of that file. You seem to believe that "under the project folder of my google test project" is your current working directory, but your test result implies that it is not. Commented Jan 7, 2023 at 2:21
  • 1
    just to test it out if the file "input.txt"; is found by the code OR not; just specify the full file path in the variable 'filename'. example: std::string filename = "C:\\Users\\Tong\\source\\repos\\BookLibrary\\GoogleTest\\input.txt"; (use the double slash for escaping) Commented Jan 7, 2023 at 2:33
  • 1
    @TongZhao you can find an answer here. Commented Jan 7, 2023 at 2:46