Error injection testing is the process of injecting an error into an application that is intended to be tested, and then running the application to verify its error handling. Error injection testing can take many different forms. In this month's column, I'll show you how to use the components of the TESTAPI library to introduce errors to. NET applications at run time.
To understand what I'm talking about in this column, it's best to look at the screenshot shown in Figure 1. This screenshot shows that I am doing an error injection test on a virtual. NET WinForm application named TwoCardPokerGame.exe. A C # program named FaultHarness.exe is running in the command shell. It changes the normal behavior of the application to be tested, so when the user clicks the button labeled Evaluate for the third time, the application throws an exception. In this case, the two card Poker application does not properly handle application exceptions, resulting in a system-generated message box.
Figure 1 Error injection test in run
Let's take a closer look at this scenario and consider some relevant details. When you start FaultHarness.exe from the command shell, the tool prepares the profiling code in the background that intercepts the normal code execution of the TwoCardPokerGame.exe. This process is called an error injection session.
The error injection session uses a DLL to initiate monitoring of the calling application Button2_Click method, which is the event handler for a button labeled Evaluate. The error injection session has been configured so that when the user clicks the Evaluate button twice before, the application runs in code, but the third time the error session causes the application to throw a system.applicationexception type of exception.
The error session logs session activity and logs a set of files to test the host. Note that in Figure 1, the first two clicks of the application deal-evaluate work fine, but the third click generates an exception.
Next, I'll briefly introduce the virtual two card Poker Game application to be tested, provide and detail the FaultHarness.exe program code shown in Figure 1, and provide tips on when to use error injection testing and when to better use other technologies. Although the FaultHarness.exe program itself is very simple, most complex work is performed by the Testapi DLL in the background, understanding and modifying the code I provide here to meet your own test scenario requirements requires you to fully understand the. NET programming environment. That is to say, even if you are a. NET beginner, you should be able to easily understand what I am introducing. I'm sure you'll find it interesting to explore error injection, which can be a useful addition to your toolset.