Here is a simple but effective general method for debugging complex application plus some C# example.
Debugging is an integral part of any software development process. Once I write some piece of code, my following action is running the application for making sure that it works correctly. Often running once is not enough for testing all the cases and often I find some bugs which enforce me to find what is wrong, fixing the bug and then testing again. This process can repeat several times until reaching the required outcome.
The process of debugging can be very slow in cases where each execution of the application takes a lot of time. One trick I usually use for accelerating the development process is implementing new features as separate modules that can be tested separately. Building a software in a modular way is always a good practice and it also can save debugging time. Only after testing the separate module separately and making sure that it is working well, I integrate it into the whole system and only then I test the new feature as a part of the entire system.
The trick of writing the new piece of code into a new separate module is good but not always possible because of the way in which the existing software is sometimes written. Additionally, sometimes I need to make a very small change in a very big system. In cases like this, testing the new code by itself is pointless and only testing the entire system is meaningful.
Adding Automation Code
When executing the application takes a lot of time, I usually try to reduce the execution time by automation. Automation allows me as a developer to run the application in a special mode which saves time by skipping stages and processes that are not relevant to the feature or bug that I am currently dealing with. Such stages and processes can be: filling a login screen, connecting some hardware, built-in self-test, selecting a patient from a list and many more. In some systems that I saw, it can take several minutes before you can actually start working.
Recently I had to solve some complex problem in some huge medical system. It was a multidisciplinary software system that was developed for years by several developers. Its 30GB source code folder contains hundreds of libraries and many third party dependencies. The most challenging part in the task was debugging it, because loading the application and navigating between its screens for getting to the relevant part of it took me about 10 minutes every time. So I decided to add some automation into it in order to ease my work. The huge software was written in C# with WPF but the technic I used can be applied with any other programming language.
I added into the solution a DLL project with a public singleton class in order that all the other parts of the system can access it. This singleton class is responsible for reading a CSV file with a set of parameters once the application is loaded and it allows any other module to check the values of these parameters. The CSV file is created in the first execution with default values in the same folder as the executable file. Once this infrastructure was ready I added many “if” statements all over the source code for allowing skipping many operations once some parameters are defined as “on” in the CSV file. This allowed me switching on and off some features by only changing the CSV file and without re-compiling in order to get quickly to the point which interested me.
Later I added into this DLL classes and functions for dumping data to files and for profiling and other things that helped me to debug the system.
The C# Code I Use
Here is the original code without the later additions which is general enough for being used in other projects.
How To Use It
If for example you want to allow yourself to skip the login screen, add the following code into the load event handler of the login screen:
You can copy this code snippet from the following block:
string user = DebugValues.GetValue(“user name”, “user”);
string password = DebugValues.GetValue(“password”, “password”);
if (DebugValues.IsOn(“skip login”))
// add here code that fills the username and password fields
// and clicks the login button
After running the application at the first time and getting into the login screen, assuming the name of the executable is “test.exe”, a CSV file with the name “test.exe.debug.csv” will be created automatically in the same folder as the executable.
Now you can open this file using Excel or just any text editor.
Now whenever you want to skip the login screen, just change the value of “skip login” parameter to “on” (by changing cell B3). You may prefer using a simple text editor because saving a change into a CSV using Excel requires clicking “yes” 4 times before closing the file.
Make sure to close Excel before starting the application because otherwise it will crash because the file will be locked by Excel.
The method which was described here helped me significantly to complete the task in short time. I think that this method could be also very useful for other development projects.
Originally published at https://www.orensifri.meddevsoft.com.