title: How do you setup Google Test in VS 2019 from scratch?
body: <p>I've been trying to set up google test v1.10 in visual studio 2019 for a really long time now and it hasn't been working, and a lot has changed as well. Most of the tutorials are out of data and Microsoft help page says to use the google test adapter but I have an already existing project that I want to add google test. I've referred to the google test installation page(<a href="https://github.com/google/googletest/blob/master/googletest/README.md" rel="nofollow noreferrer">https://github.com/google/googletest/blob/master/googletest/README.md</a>) and tried to set it up using the cmake method but it isn't working and the cmake method is a bit complicated. I was wondering if anyone could help with the steps for a dummy like me? I feel like this will also help people who are trying to set it up currently and are stuck as well.</p>
  <p>This is what i did for the cmake thingy:</p>
  <ol>
  <li><p>created an empty project in vs, and added a source.cpp file and a Header.h file(for the example).</p>
  </li>
  <li><p>I created a CMakeLists.txt and a CMakeLists.txt.in file and copy pasted this in
  for the first one(tweaked a bit for my project)</p>
  </li>
  </ol>
  <pre><code># Download and unpack googletest at configure time
  configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
  execute_process(COMMAND ${CMAKE_COMMAND} -G &quot;${CMAKE_GENERATOR}&quot; .
    RESULT_VARIABLE result
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
  if(result)
    message(FATAL_ERROR &quot;CMake step for googletest failed: ${result}&quot;)
  endif()
  execute_process(COMMAND ${CMAKE_COMMAND} --build .
    RESULT_VARIABLE result
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
  if(result)
    message(FATAL_ERROR &quot;Build step for googletest failed: ${result}&quot;)
  endif()
  
  # Prevent overriding the parent project's compiler/linker
  # settings on Windows
  set(gtest_force_shared_crt ON CACHE BOOL &quot;&quot; FORCE)
  
  # Add googletest directly to our build. This defines
  # the gtest and gtest_main targets.
  add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
                   ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
                   EXCLUDE_FROM_ALL)
  
  # The gtest/gtest_main targets carry header search path
  # dependencies automatically when using CMake 2.8.11 or
  # later. Otherwise we have to add them here ourselves.
  if (CMAKE_VERSION VERSION_LESS 2.8.11)
    include_directories(&quot;${gtest_SOURCE_DIR}/include&quot;)
  endif()
  
  # Now simply link against gtest or gtest_main as needed. Eg
  add_executable(test_ source.cpp)
  target_link_libraries(test_ gtest_main)
  add_test(NAME example_test COMMAND test)
  </code></pre>
  <p>and CMakeLists.txt.in</p>
  <pre><code>cmake_minimum_required(VERSION 2.8.2)
  
  project(googletest-download NONE)
  
  include(ExternalProject)
  ExternalProject_Add(googletest
    GIT_REPOSITORY    https://github.com/google/googletest.git
    GIT_TAG           master
    SOURCE_DIR        &quot;${CMAKE_CURRENT_BINARY_DIR}/googletest-src&quot;
    BINARY_DIR        &quot;${CMAKE_CURRENT_BINARY_DIR}/googletest-build&quot;
    CONFIGURE_COMMAND &quot;&quot;
    BUILD_COMMAND     &quot;&quot;
    INSTALL_COMMAND   &quot;&quot;
    TEST_COMMAND      &quot;&quot;
  )
  </code></pre>
  <ol start="3">
  <li>I created a build folder in my project file</li>
  <li>I used the cmake command from the terminal to build it into the build folder
  like this</li>
  </ol>
  <pre><code>cmake -S &quot;path to src code&quot; -B &quot;path to build&quot;
  </code></pre>
  <p>and these are the warnings I got:</p>
  <pre><code>No project() command is present. The top level CMakeLists.txt file must contain a literal, direct call to the project() command. And a line of code such as
  
  project(projectName)
  
  near the top of the CMake file, but after cmake_minimum_required().
  
  CMake is pretending there is a &quot;project(projectName)&quot; command on the first line.
  
  This warning is for project developers. Use who-dev to supress it.
  </code></pre>
  <p>other than that it did the building
  and this is my project tree currently
  <a href="https://i.stack.imgur.com/6UDd1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6UDd1.png" alt="enter image description here" /></a></p>
  <p>and this is what's there in /build</p>
  <p><a href="https://i.stack.imgur.com/NinZw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NinZw.png" alt="enter image description here" /></a></p>
  <p>but idk what to do after this? How do I start creating tests? If possible i want to create another project inside my current solution so i can run tests separately</p>
  <p>here's what is mean</p>
  <p><a href="https://i.stack.imgur.com/5y9OP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5y9OP.png" alt="enter image description here" /></a></p>
  <p>the googletest project is where i want to run my tests if possible</p>
  <p>and this what my project tree looks like after</p>
  <p><a href="https://i.stack.imgur.com/QJUoT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QJUoT.png" alt="enter image description here" /></a></p>