Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been asked to do a small side-project to supply a simple application to on

ID: 643070 • Letter: I

Question

I've been asked to do a small side-project to supply a simple application to one of our customers. Normally I would be working on back-end code where I have all of my testing needs figured out, and I've not yet had the dubious pleasure of writing tests for the GUI, so it's a little unclear to me how I should set up the testing code and tools for an EXE. My first instinct was to simply include the tests with the application code, however that would require supplying a number of test-specific dependencies, which I have been instructed to specifically not ship to the customer. I am also unable to squeeze out any cash for a purpose built test tool, so I need to use the tools I have at hand (StoryQ, RhinoMocks, and NUnit), which really should be more than enough to test the behavior of a simple GUI app. So as far as I can see, this leaves me with trying to strike a good balance between keeping the design really simple, or purposefully over-engineering for the sake of the tests. It seems I'm either building the app with the business logic in a separate library and testing against the library as I usually would, or finding some other mechanism to allow me to the executable without breaking out additional modules that the application design doesn't really need. Edit: Please note that this question is about how to structure the relationship between NUnit and my executable - as opposed to a DLL - and not about how to separate presentation and business logic. /Edit So my question is: Is there a specific/recommended method for configuring a simple GUI application with unit tests to allow me to adequately check state and behavior, using the tools I have at hand, and without resorting to over-engineering? Have I missed something fundamental about the way NUnit should be invoked/configured when testing an EXE (as opposed to a DLL)? Can you provide or point me in the direction of examples of how achieve all of this? I realize that there may be more than one way to do this so I'm looking for specific implementation guidelines based on your experience.

Explanation / Answer

I think that:

Your business test code should be in a separate project, testing your business code library.
Your GUI test code should be in a separate project, testing your GUI library. Now, how to build a GUI library instead of an executable, I attempt to answer that later.
If you have a my.namespace.biz.MyClass, your test class should be my.namespace.biz.MyClassTest (or MyClassTestCase).
If you want to test the code found in your executable target, then you should have a setup that builds an EXE, and another setup that builds a library (DLL) which is the one that you will launch your tests against.
These are the rules that I like to follow, whether it's Java or C# (except there is no EXE problem with Java of course :-) )

As for how to configure your test environment, it seems to me that you have at least these two choices:

Using MSBuild

Create a clone of your .proj file (say myproject-as-dll.proj). Change the OutputType in the cloned file from "EXE" to "Library". Using the MSBuild command you are now able to produce a library you can set as reference into your project containing NUnit test cases.

It seems to be possible to me, but I've never used it that much honestly, so I'm not sure. Plus, you may not have MSBuild on your integration test server, and I don't know if it can be separated from Visual Studio...

Using NAnt

If you are not familiar with NAnt, you will have to google up how to configure your project builds with it. Maybe check out this, it is a bit old but the author has commented the NAnt files and If find it self explanatory.(Edit: examining his file more in detail, I find his configuration file extremely reusable). He also does much more than just build, since he executes test cases and launches code coverage tools. Now, I admit I've never used NAnt, contrary to its Java counterpart and father "Ant" that I've used a lot but I see it's quite the same thing and I don't think it's that difficult to learn.

With that tool you can come up with a configuration that will allow you to:

build all your projects (business logic, GUI, etc.) into separate libraries
build your test projects
launch the tests (that specific part is done with the NUnit2 task).
examine your code coverage with the NCover task.
With a bit of more code, you could even:

perform nightly deployments in your integration server
if NAnt is available in your integration server, launch nightly integration tests with the help of scheduled tasks
All is done without changing anything in your Visual Studio files. And, really, it does not look like over-engineering to me, it's just one file. It might take you one, maybe two days to make it all work but you'll have in my opinion a good setup.

Lastly, I would give to the client all that is necessary to build, test and run the projects. I tend to think it shows your professionalism and the fact that you write code with quality in your mind (which it seems to me you do since you're looking for elegant solutions)