I have 2 projects, one is MFC project, it compiled output type is EXE dialog, the other is a CppUnit project in order to test the MFC project.
I create the Cppunit project as windows Console Project with MFC headers and set up the Cppunit environment, because of MFC project output type is Exe, so I change the project form Exe to lib for test, and add the MFC project's headers in Cppunit project, create an instance from MFC project, then call some functions to test.
but the question is the Cppunit and MFC project all have "theApp" instance, this 2 theApp can't build in Cppunit project.
how to avoid this problem to build success?
is the Cppunit can test the type of project?
I have a sligtly different way to do it. See if it works.
You better create test project with in the solution it self.
Right click solution->Add->NewProject
Select under Test->Native Unit Test Project.
This way you will see your test project as a DLL and no additional APP object.
How to refer your MFC dialog in test project?
Under test project, you will see a References directory, Right click it and select Add Reference. You will notice your MFC dialog application and select it.
Now you can add any dialog related header files in your test project and start writing test methods.
How to run test methods?
From the menu items of Visual Studio, select Test->Windows->Test Explorer.
All your test methods will appear, you can test a specific one or all at a time
Related
I have a solution which containes serveral projects (An MFC Application and the others are DLL projects). Is it possible to add another console application project (BOOST TEST) to unit test a specific DLL project, without modifying anything in the production MFC application and succeeding in building the whole solution?
I want only the test console application to run as a post build and then launching the prodution MFC application.
I wrote a series of blog posts on test-driven development in C++ that show you step-by-step how to do TDD in C++ with Visual Studio and Boost.Test. The steps would be nearly identical for your situation with the exception that your console test project depends on the DLL project instead of the static library project that I used in my article.
If I understand you correctly you want the build of the solution to compile and run the tests. If you say "build and run in the debugger" (F5), you want to compile all the code, run the tests and then run the application if the tests pass. This is not hard to do.
Set up the console unit test program as outlined in my blog posts and that will make the unit test project compile and run as part of the build. So if you say "build and run in the debugger" (F5) in Visual Studio, it will build the solution and then run the startup project, e.g. your MFC application. Since the solution contains the unit test console executable project, it will build that project. The unit test project has the post-build step to execute the tests, so the tests will run as part of the build.
Because your unit test executable depends on a DLL, you will need to make sure the DLL is found by the executable at run-time. You may need to add additional commands to your post-build step to copy the DLL to the necessary directory before running the test executable. You can verify this works properly by setting your unit test project as the startup project and running it in the debugger.
Double check in the configuration manager that all the projects are set to build for your combination of platform and configuration. Sometimes if you have customized these in your solution when you add a new project it isn't automatically checked to compile in the custom platform/configuration combination.
If this isn't working for you, then add a comment or edit your question to include more specifics about what isn't working.
So, this is what I have done.
I had a c++ project that I imported in NetBeans. Since the code had its old makefile I made NetBeans use it. I then added the logical folder Test Files (and included cppunit libraries in its linker). If I now try to add a cpp unit test Netbeans complains that I do not have a Makefile and does not let me create the unit test.
The exact error message is:
Makefile is not detected. Test targets will not be added to makefile.
How should I modify my old makefile so that Netbeans will recognize it?
Thanks for the help,
Michele
Additional information
I followed the instruction in http://www.oracle.com/technetwork/articles/servers-storage-dev/howto-add-unittests-ide-1731716.html#About on adding test to an unmanaged project but I cannot understand point 6. What should I add to my makefile? Can someone give me an example?
Right-click on the project name in the Projects pane - you'll get a pop-up menu with first line New, place cursor on this line - another pop-up menu will be opened, left-click on the CppUnit Test... in this menu. You'll get a pop-up window with some settings you can adjust.
After you click Finish in this window the NetBeans will create a directory with test skeletons and add new targets to your Makefile.
Good luck!
I ran into the same problem. It appears in NetBeans you MUST have the Test Package, which is where you would add your unit tests. If you create a C++ Application in NetBeans you will see the Test Package in your project. If you have a project that uses a Makefile that was not generated by NetBeans, then it appears that there is no way to add this Test Package to your project. I would be very happy to be wrong but this has been my experience and from all I have read it appears to be true.
I'm trying to add a new statically linked library to a Qt-based application.
I used this guide: http://doc.qt.nokia.com/qtcreator-snapshot/creator-project-qmake-libraries.html
But when I get to step 4, which says "In the Add to project list, select a project. For example, myapp", I'm unable to do this because the Add to project list is disabled (gray) in the Project Management dialog.
What is required for Qt Creator to recognize other projects at this point, such that they appear in the list (which would then, presumably, no longer be disabled)?
I'm working on Linux/GNU, on a PC machine.
See the post here: http://lists.qt.nokia.com/pipermail/qt-creator/2010-December/008166.html
Your "library" project and your "application" project both need to be part of a "Subdirs" project.
First, create a Subdirs project, which will contain all the individual projects for your overall project (this is like a "Solution" in Visual Studio).
Then, create your library project, by right-clicking the "subdirs" project, and selecting "New Subproject...", and then follow the instructions from the QtCreator docs, and the overall project should be available in the drop-down.
Finally (assuming you want to create a dependency from an application to your library), create your application project as a sub-project of the overall project, and then you can add your library project as an "internal library" of your application project.
Using Visual Studio 2010 C++ with googletest. I'm new to unit testing and I've created a test solution to experiment with it. I have three projects in the solution:
HelloService (static lib)
HelloService.Tests (exe, a console app I think, linked with gmock_main.lib)
HelloApp (MFC exe, my main app)
I've got googletest (and googlemock) compiled linked and successfully working. My question is with the code test development cycle. I'm trying to understand the proper workflow with testing. Currently if I set HelloService.Tests as the "StartUp project" then when I hit F5 the tests run, but my HelloApp doesn't. If I set my HelloApp as the startup project then when I hit F5 my app runs but my tests don't.
I would think that I would want my "HelloApp" as the startup project but my tests to run when I build it and before I run it. Is that right? How do I set it up to do that?
The solution for me was to set the HelloApp as the StartUp project and then right click on the HelloApp project and choose "Project Dependencies..." and then check the HelloService.Tests project (the HelloService project was already checked). Now when I hit F5 the test project gets run (because HelloService.Tests already had a post-build event on it to run itself)
My only concern is if creating a project dependency creates some kind of code dependency. My guess is it doesn't but I'd like to know for sure.
You can set a post-build event on your tests project to run the test executable. Then, adding the test project as a dependency of the main app will run the tests automatically with each build. This does mean that the build will fail if any tests fail. It's up to you to decide whether to still run the app or fix the failing tests first.
I'm using Visual Studio 2008.
I have a solution with two projects. One builds a DLL, which is my "production code". The other builds a console app exe, which is my unit test suite.
For my unit test project, I have listed as linker inputs the names of the source modules from the DLL. I.e., I have a DLLMain.cpp in the DLL project, and a linker input "DLLMain" in the exe project. This allows the exe to link with the obj files produced by the DLL project, preventing recompilation of those modules just for the unit tests. (Saves a lot of build time.)
THE PROBLEM IS that because the exe is produced later than the obj's, and by a different project, its timestamp is always newer than the obj's. So when you try to run or debug, it ALWAYS says the exe project is out of date and needs to be rebuilt.
Is there some way I can configure the exe project to ignore the timestamps? Or is there some other, perhaps more general, solution I'm not seeing here?
Seems like you are creating foo.obj in the DLL's project, linking foo.obj in the DLL project to produce the DLL, and then linking foo.obj to your EXE project without first recompiling it.
I have never done this before, but first thing I would check is to make sure the Intermediate Directory settings are the same for both the EXE project and the DLL project.
Go to the project that is not needed for unit testing
Right click on it and press Properties
Click on Configuration manager
Add a new configuration using the first drop down list
Click ok
Select that configuration in the window that is now focused
then in configuration properties set "Excluded From Build" to yes