-
-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use doctest in dll only(without main.cpp and .exe) #299
Comments
since you'll be defining the entry point (in this case On the resharper stuff - I suggest you follow their instructions on how to integrate doctest and discover tests and whatnot - I'm still not familiar with their plugin for Visual Studio (but am really happy that they worked on that!). Also you'll be needing And another note: you could remove the Let me know if this helps :) |
Updated code. // dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#define DOCTEST_CONFIG_IMPLEMENT
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include <cstdio>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
doctest::Context context{};
const auto doctestResult = context.run();
if (context.shouldExit())
return doctestResult;
return TRUE;
}
TEST_CASE("test dll") {
printf("I am a test from the dll!\n");
}
DOCTEST_SYMBOL_EXPORT void from_dll(); // to silence "-Wmissing-declarations" with GCC
DOCTEST_SYMBOL_EXPORT void from_dll() {} // force the creation of a .lib file with MSVC
Is it possible to run this test without exe? If so how? I cant get it to run since its only dll. Using resharper also doesnt help(if it need to re-configure, i dont know how). Probably impossible since it somehow need a test runner. Not sure. Thanks. for replying. |
My situation is, I have multiple dlls. Around 20 i guess. Right now I create doctest context in my main which will call all the dlls and run the test. Ideally, i would like the ability to execute the test on the dll only. Meaning that only compile specific dll, and run the desired test inside the dll. its faster since it only compile the specific dll(and its dependencies). I assume that in each dll, we could supply DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN so that a main will be created which will call the dll behind the scene. Maybe thats not the case. Anyway, what are your thoughts. |
In order to execute tests in a .dll you will need an .exe to load it - this is true even without tests - if you need the code in a .dll to be used someone needs to load/use it. If you want to compile only a specific .dll and execute the tests in it, you'll need a separate project which compiles to an .exe and links against the .dll (or loads it at runtime with In the code which you provided you're writing your own main() function (DllMain in this case) - that means you only need |
after our discussion in the gitter channel I suppose we could close this issue? :) |
I have a Windows GUI host, and a doctest DLL with all the test cases. From inside the DLL, how can I specify to output the test messages to a text file? Also is there a way to attach to a console and see the messages? |
Description
I created a simple dll project from visual studio 2019(using the wizard) and then I add doctest.h and a test in the dllmain.cpp.
The dllmain.cpp looks like this.
While the code compiles, i cant
Probably because without main, there is no test runner.
Is it possible to create test inside a dll and test it without main?
The text was updated successfully, but these errors were encountered: