I am not sure about the correct useage of the test function. As far as I understand it the usual workflow is to add a test_package which then may consume the actual package at package creation time or explicitly when the test method is called.
But it is not possible to call test before the package is added to the local cache and it is also not possible to define the test method in the same conanfile, as this leads to an error of a reflexive dependency.
This means - please correct me if I am wrong - A test_package, which may include unit tests and similar stuff will never be added to a conan cache.
So am I correct that there is no way to directly call the test method while still developing the package without it beeing in the local cache?
And it is also not possible to just add a test method to the actual conan file instead of using an extra conan test_package.
Beeing that the case this also means that by separating the testing stuff in this extra package it is not possible to automatically run those tests, when the package has to be build from source on an other operating system, as the test_package won't be available there?
Currently I have solved it in my project by calling the testing stuff directly post build, but of course it would be good to be able to call the testing routines without calling build previously.
A test_package, which may include unit tests and similar stuff will never be added to a conan cache.
The tests of the library should be run in the "build" method, not in the test_package, for example with cmake.test() or any other "framework".
The test_package is only intended to check if the package is correctly built, typically running some compilation with the created package and any other check you want to do in the destination package folder.
Thank you for clarification and explaining the difference about what should be tested where. I didn't notice the -t option of the build call due to the fact that I was so focused on the documentation for the test command.
I'd suggest to maybe add a hint at the test command documentation https://docs.conan.io/en/latest/reference/commands/creator/test.html about the build -test option.
Most helpful comment
The tests of the library should be run in the "build" method, not in the test_package, for example with cmake.test() or any other "framework".
The test_package is only intended to check if the package is correctly built, typically running some compilation with the created package and any other check you want to do in the destination package folder.