{"id":664,"date":"2017-07-23T10:17:12","date_gmt":"2017-07-23T10:17:12","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=664"},"modified":"2024-02-16T10:29:12","modified_gmt":"2024-02-16T10:29:12","slug":"unit-testing-with-google-test","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=664","title":{"rendered":"Unit testing series &#8211; Test without double (Part 3)"},"content":{"rendered":"<p>The first test szenario isn&#8217;t using a double.<\/p>\n<hr>\n<p><strong>Test<\/strong><\/p>\n<pre class=\"brush: cpp; gutter: false; title: UserInterfaceTest.hpp; notranslate\" title=\"UserInterfaceTest.hpp\">\r\n#pragma once\r\n#include &quot;WindowManager.hpp&quot;\r\n#include &quot;UserInterface.hpp&quot;\r\n#include &lt;gtest\/gtest.h&gt;\r\n#include &lt;memory&gt;\r\n\r\nclass UserInterfaceTest : public testing::Test\r\n{\r\nprotected:\r\n  virtual void SetUp();\r\n  virtual void TearDown();\r\n  std::shared_ptr&lt;IWindowManager&gt; m_windowMgr;\r\n  std::unique_ptr&lt;UserInterface&gt; m_userInter;\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; gutter: false; title: UserInterfaceTest.cpp; notranslate\" title=\"UserInterfaceTest.cpp\">\r\n#include &quot;UserInterfaceTest.hpp&quot;\r\n\r\nvoid UserInterfaceTest::SetUp()\r\n{\r\n  m_windowMgr.reset(new WindowManager(100, 100));\r\n  m_userInter.reset(new UserInterface(m_windowMgr));\r\n}\r\n\r\nvoid UserInterfaceTest::TearDown() {}\r\n\r\nTEST_F(UserInterfaceTest, loadWindow)\r\n{\r\n  bool done = m_userInter-&gt;loadWindow(50, 150, 50, 150);\r\n  EXPECT_NE(done, true);\r\n}\r\n<\/pre>\n<hr>\n<p><strong>App<\/strong><\/p>\n<pre class=\"brush: cpp; gutter: false; title: Main.Test.cpp; notranslate\" title=\"Main.Test.cpp\">\r\n#include &lt;gtest\/gtest.h&gt;\r\n\r\nint main(int argc, char **argv)\r\n{\r\n  testing::InitGoogleTest(&amp;argc, argv);\r\n  return RUN_ALL_TESTS();\r\n}\r\n<\/pre>\n<hr>\n<p><strong>Exec<\/strong><\/p>\n<pre>\r\n$ g++ -c UserInterface.cpp WindowManager.cpp\r\n$ ar rcs libwnd.a UserInterface.o WindowManager.o\r\n$ g++ UserInterfaceTest.cpp Main.Test.cpp libwnd.a -lpthread -lgtest\r\n$ .\/a.out \r\n[==========] Running 1 test from 1 test case.\r\n[----------] Global test environment set-up.\r\n[----------] 1 test from UserInterfaceTest\r\n[ RUN      ] UserInterfaceTest.loadWindow\r\n[       OK ] UserInterfaceTest.loadWindow (0 ms)\r\n[----------] 1 test from UserInterfaceTest (0 ms total)\r\n\r\n[----------] Global test environment tear-down\r\n[==========] 1 test from 1 test case ran. (0 ms total)\r\n[  PASSED  ] 1 test.\r\n<\/pre>\n<hr>\n<ul>\n<li>Prev: <a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=6054\">Unit testing series \u2013 Test scenario (Part 2)<\/a><\/li>\n<li>Next: <a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=858\">Unit testing series \u2013 Test with Stub (Part 4)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The first test szenario isn&#8217;t using a double. Test App Exec $ g++ -c UserInterface.cpp WindowManager.cpp $ ar rcs libwnd.a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[33],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/664"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=664"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions"}],"predecessor-version":[{"id":16770,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions\/16770"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}