1

I will start writing my first unit tests for a project soon, and I plan on storing them in a directory called test. Inside this directory, I have been advised to have another main.cpp file, in addition to other main.cpp in my src directory.

Does the compiler build two executables or something? How can you run this test inside an IDE? I am using codelite, which appears to have some support for UnitTest++, but I plan on using Boost Test.

Taylor
  • 1,797
  • 4
  • 26
  • 51
  • Yes generally in unit testing you would have a test harness executable that exercises as much of the codebase as possible. You would compile `TestSuite` which has it's own main which would simply invoke the unit tests. – Justin Randall Dec 14 '17 at 04:50

1 Answers1

1

Yes, you will have multiple executables.

  1. Your product, custom main.
  2. Your unit tests, main produced by boost or gtest or whatever.

This is not something the compiler does, but something you will need to set up. For example in Visual studio you might set up multiple projects as such:

enter image description here

You can see there are 2 projects. Both are executable and one runs the product, the other runs tests.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
  • 1
    thanks, but I'd still like to see how to do this on codelite. I'm having trouble linking files from my original project to this test project: https://stackoverflow.com/questions/47821458/trouble-linking-object-files-from-project-in-tests – Taylor Dec 14 '17 at 22:24