Let's say you need to implement the following feature. I have a GUI application with my business logic. The model is rather nontrivial, and I want to implement the so-called debagging. In other words, I want to track the model change step by step (for example, by pressing the F10 key). I would like to ask, what is the most adequate solution to this problem? At the moment, I see two potential solutions:

  1. Taking the work with the model to a separate thread (when the debug mode is on, after each notification of a change, the flow with the model stops, so that the gui can be updated, by pressing f10 - the stream wakes up)
  2. Implementation based on the creation of another internal message loop (on each notification of a model change, we create a new cycle using Dispatcher.PushFrame, and disable the ability to change the model)

I do not want to fence the bike, can there already exist proven approaches?

  • If you understand correctly, this is not "testing" but just step-by-step execution. I do not see the problem of implementing this as an additional option (if you want you can call it a mode). To put it simply, imagine the task as a list of sequential operations where the result at each iteration will not be принципиально different from the final one. That is, simply return the transition state in this way filling the list (the specific data type will depend on whether you give the opportunity to go back a step or only forward) - user227049
  • @Foggy Finder, roughly speaking, do you want to use the analog undo / redo list? If yes, then it is not clear what exactly should keep this list - action games that update gui? - LmTinyToon
  • No, just состояния . It would be easier to explain with an example. Do you have the opportunity to describe the task more specifically? - user227049
  • Well, for example, I have a tree. Let it display some arithmetic action. Changing node values. Changes related nodes. As soon as the model state of the node changes. There is an alert gui. - LmTinyToon

1 answer 1

It seems to me that a well-established approach is to debug the program in parts .

When you test your model, you don't care if you have a UI. You simply feed the input values, run the model, and make sure that it produces the desired result. (It may be worth automating in the form of unit tests.) And you can watch the value of your variables in the debugger, you don’t need a UI for this.

When you test business logic / VM, in simple cases you can also just pass the necessary pieces under the debugger, you do not need for this UI. In complex cases (for example, many asynchronous events, which the debugger doesn’t affect in the best way), get adequate logging.

To test the UI, the easiest way is to break the complex UI into separate controls ( UserControl , DataTemplate , etc.), and test them separately on a test application.


If you notice that you need to wait for the UI reaction to debug business logic, you have something wrong with the architecture: your business logic is partially at the UI level! (Example: you have two VMs connected through Binding in the UI. This is bad and wrong.) Make sure that the business logic is running as needed and in the absence of a UI. This eliminates debugging problems, and improves the modularity of your application.

  • Maybe I put it wrong. I want to implement testing the model with gui. A simple example - my application works with a visual representation of the tree. What the tree represents is not important. But, doing something with a tree node, the model can change, I would like to see what happens step by step with the tree. View all this through the GUI. - LmTinyToon
  • one
    Perhaps the word testing here is not entirely appropriate. Just such is the analogue of the team step over - LmTinyToon
  • one
    @LmTinyToon: Testing the model using the UI is exactly what no one does. The model is usually tested using unit tests: they write code that interacts with the model and assesses how well the responses from the model correspond to the expected behavior (that is, the TK). - VladD
  • @LmTinyToon: So I’m not saying that you can’t do that , maybe you can. But you asked about generally accepted practices? - VladD
  • Well, there are programs that use a similar approach - for example, visual programming languages ​​(where the tree is a program, and you can test this tree through gui) - LmTinyToon