开发者

Visual Studio 2010: Building and development cycle with Google Test?

开发者 https://www.devze.com 2023-03-15 20:49 出处:网络
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:

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 projec开发者_高级运维t 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号