How to exclude Unit Test at compile time

Basile Perrenoud

I am currently refactoring parts of a qt/c++ application for my company and they have absolutely no unit tests.

I would like to add some, but I actually never did the setup for testing so I am not 100% sure of the best way to proceed. Here is what I was thinking (feel free to comment on this, but it is not my main question)

  • I'll use the QTest library since we use QT and I don't want to add another lib to the project
  • In each subfolder of the src directory, I'll add a test folder with test classes that correspond to the classes found in the directory (the goal is to keep test classes close to what they test)

My question is: How do I (or should I) prevent the test classes to be compiled / included in release? I mean, if I manage to get a large test coverage, this will be plenty of new test code to compile, which is useless for the application itself. Can we (should we) exclude this code in release versions? What is the common practice (if there is one)?

B. DiKi

If you are using CMake, in your CMakeLists, you can define what files are used in your current build.

In the same CMake, you can define a different target that includes your tests files. The location of the files don't matter, they can be in the same place as your code

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to unit test code that should cause compile error

From Dev

Exclude test dependency resolution from `sbt compile`

From Dev

Compile at run time exclude class that is generated by CodeDom

From Dev

Compile at run time exclude class that is generated by CodeDom

From Dev

Exclude part of function template during compile time

From Dev

How can I limit the maximum running time for a unit test?

From Dev

How to Unit-Test Thread which takes time to perform action

From Dev

How to Unit-Test Thread which takes time to perform action

From Dev

How to exclude Projects with names ending in ".Test" from my code coverage analysis in VS2012 Unit Tests

From Dev

Automake config cannot compile my unit test

From Dev

Unit testing compile-time weaving

From Dev

How to unit test FileContentResult?

From Dev

How to unit test DataContractSerializer?

From Dev

How to unit test if "." is not on @INC?

From Dev

How to unit test FileContentResult?

From Dev

Is there a way to test at compile-time that a constant is a compile-time constant?

From Dev

How to time condition at compile time

From Dev

Exclude Spring Cloud Config Server from Spring boot unit test

From Dev

Total unit test execution time is gone

From Dev

Total unit test execution time is gone

From Dev

Gradle dependency for compile time only and test

From Dev

Test for expected compile time errors in java

From Dev

How can I compile only the Spark Core and Spark Streaming (so that I can get unit test utilities of Streaming)?

From Dev

Spring4 MVC Unit test does not compile

From Dev

Element with directive doesn't $compile properly in unit test

From Dev

Can I compile numba in the setup phase of a unit test?

From Dev

Unable to compile transcluded directives in unit test as of Angular 1.3.0

From Dev

C2338 compile error for a Microsoft Visual Studio unit test

From Dev

How to unit test PHP traits

Related Related

  1. 1

    how to unit test code that should cause compile error

  2. 2

    Exclude test dependency resolution from `sbt compile`

  3. 3

    Compile at run time exclude class that is generated by CodeDom

  4. 4

    Compile at run time exclude class that is generated by CodeDom

  5. 5

    Exclude part of function template during compile time

  6. 6

    How can I limit the maximum running time for a unit test?

  7. 7

    How to Unit-Test Thread which takes time to perform action

  8. 8

    How to Unit-Test Thread which takes time to perform action

  9. 9

    How to exclude Projects with names ending in ".Test" from my code coverage analysis in VS2012 Unit Tests

  10. 10

    Automake config cannot compile my unit test

  11. 11

    Unit testing compile-time weaving

  12. 12

    How to unit test FileContentResult?

  13. 13

    How to unit test DataContractSerializer?

  14. 14

    How to unit test if "." is not on @INC?

  15. 15

    How to unit test FileContentResult?

  16. 16

    Is there a way to test at compile-time that a constant is a compile-time constant?

  17. 17

    How to time condition at compile time

  18. 18

    Exclude Spring Cloud Config Server from Spring boot unit test

  19. 19

    Total unit test execution time is gone

  20. 20

    Total unit test execution time is gone

  21. 21

    Gradle dependency for compile time only and test

  22. 22

    Test for expected compile time errors in java

  23. 23

    How can I compile only the Spark Core and Spark Streaming (so that I can get unit test utilities of Streaming)?

  24. 24

    Spring4 MVC Unit test does not compile

  25. 25

    Element with directive doesn't $compile properly in unit test

  26. 26

    Can I compile numba in the setup phase of a unit test?

  27. 27

    Unable to compile transcluded directives in unit test as of Angular 1.3.0

  28. 28

    C2338 compile error for a Microsoft Visual Studio unit test

  29. 29

    How to unit test PHP traits

HotTag

Archive