Any valid architecture or design pattern for an MFC application?

This question has been listening to me for a while.

I am looking for a testable architectural pattern for an MFC application. Please do not tell me that MFC is already MVC or something like that, because it does not make any sense until we can test the application.

I understand that a rule of thumb is to make its View / Document as stupid as possible and make other classes verifiable. But I want to know more about this. How can I make the View / Document as deep as possible and relate them to other test classes?

At first I thought about MVP, as I had some success for Windows.NET and Android application. But in this case, MFC we need to do Document dumb too. This complicates the situation.

I need an efficient architecture that is durable. Any advice from an experienced developer would be appreciated.

+4
source share
3 answers

I don’t think you might need any special design pattern to separate the logic from the user interface. MVP may help, but it may not be practically necessary. Separation will be enough for testing if you can make your logic in separate DLLs or static libraries and make them accessible from other applications. This will be a good start to practically make your logic a test.

But even before that, I would find a good test environment for your development environment. I had some success with either Google Testing or Boost Testing in the case of MFC.

Regarding design patterns, they are very good at making your program workable and maximizing code reuse, but I'm not sure if it’s good practice to use them to make your program testable. Testability is a good feature of your program, but it may not be the goal of your design.

0
source

Testing the GUI is still a terrible task. There are tools to help you track and play interactive input. I used some of these APIs (code stolen from Perl) to inject keystroke events into another application (to open a new URL in firefox without opening a new tab). But this is not very good for testing.

Additional tools cost several kilograms of dollars and come with external script languages, and usability reports are shared. http://en.wikipedia.org/wiki/List_of_GUI_testing_tools

The GUI has two different areas. One of them fills dialogs with user parameters, and the other is testing the model / view.

The first can be easily solved with a few coding rules. For example, dialog boxes do not change anything, but they take and return classes with all parameters. In this case, you can simply replace the dialog code with your own code. This is the easy part. In my code dialogs, change the settings of the ini file, and then just notify the model with a few tips what has changed.

Testing views and models is much more complicated. If it’s a drawing, you can try using the WM_PRINT message to capture the view, and then run your test and compare its result with the previous captured data. If the bitmaps are the same, the test passes. I have never seen this technique used in the real world, with the exception of one toolkit, where he used it to verify the exact drawing of pixels on multiple platforms.

Next, a model based on interactive code is tested. As mentioned earlier, key events are easier to emulate than most translate directly to a separate command processing code anyway, so you just check the commands, not the key event handler. Selecting and manipulating the mouse, for example, selecting an object on a canvas, is much more complicated. Or use one of these testing tools that promise to capture and replay mouse actions or pray.

Depending on your own code base, there are many different ways if you are abstract from MFC good enough to use mock GUI objects instead of real MFC windows. And if you have already embedded a script language that can help you check things, etc. Sorry there is no simple template. This must be decided on a case-by-case basis.

My own experience is that I don’t like unit testing GUI and unit testing. This is often not worth the time. I use Eiffel and Design by Contract (which means a lot of claims for approval) and conducts extensive beta tests with clients and allows clients to find the remaining errors. In most cases, most errors are erratic usability errors.

+3
source

Do you mean MVC? This is there in the doc / view architecture, but part of the controller is somewhat missing. You can still achieve good things that separate the graphical interface from the data, but the real advantage of separating the model from the view is that you can use it elsewhere, but this is not easy with doc / view, to say the least.

Edit : Add: Regarding testing capabilities, the MFC application comes with command line processing. You can use this and send test commands to the application from the command line.

+1
source

Source: https://habr.com/ru/post/1386449/


All Articles