Test Method: To Debug a Test Method
The following activity will walk you through the process of debugging a test method.
Story
Suppose that you have a test method implemented in a test class. You need to debug the test method in order to detect possible errors.
Process Overview
In Visual Studio, you will set breakpoints both in the code being tested and in the test method, launch the debugging for the test method from the Test Explorer window, and check that the values of the fields are as expected.
System Preparation
Before you begin debugging the test method, make sure that you have performed the following prerequisite activities:
- Test Instance for Unit Testing: To Deploy an Instance, to prepare the MYOB Acumatica instance that you will use
- Test Project and Test Class: To Create a Test Project, to create and
configure the
PhoneRepairShop_Code.Tests.csproj
test project - Test Project and Test Class: To Create a Test Class, to create the
RSSVRepairServiceMaintTests
test class - Test Method: To Create a Test Method Without Parameters, to
create the
PreliminaryCheckAndWalkInServiceFlags_AreOpposite
test method
Step: Debugging a Test Method
To debug the
PreliminaryCheckAndWalkInServiceFlags_AreOpposite
method, do the following:- In Visual Studio, open the RSSVRepairServiceMaintTests.cs file.
- Move the caret to the following
line.
repairService.WalkInService = false;
- Press F9 to set a breakpoint on the line.
- Open the RSSVRepairServiceMaint.cs file.
- In the
_(Events.FieldUpdated<RSSVRepairService, RSSVRepairService.walkInService> e)
method, move the caret to the following line.row.PreliminaryCheck = !(row.WalkInService == true);
- Press F9 to set a breakpoint on the line.
- Select the Test Explorer window. menu command to open the
- Right-click the
PreliminaryCheckAndWalkInServiceFlags_AreOpposite
method, and select Debug. After the debugging process starts, the execution initially pauses at the breakpoint in the RSSVRepairServiceMaint.cs file. This is because the_(Events.FieldUpdated<RSSVRepairService, RSSVRepairService.walkInService> e)
method gets triggered when therepairService
object is first created and added to the cache using thegraph.Caches[typeof(RSSVRepairService)].Insert(...)
method of the graph. Continue debugging (you can press F5 for this). - The execution pauses in the
RSSVRepairServiceMaintTests.cs file. You can verify
that the value of
repairService.WalkInService
is true. - Step over the statement in the current line (you can use F10 for this). The
value of
repairService.WalkInService
becomes false. - Step over the statement in the current line. This updates the
repairService
object in the cache. During the update, the FieldUpdated event is generated for the Walk-In Service check box, and the_(Events.FieldUpdated<RSSVRepairService, RSSVRepairService.walkInService> e)
method of theRSSVRepairServiceMaint
class is launched. The execution pauses at the breakpoint in the RSSVRepairServiceMaint.cs file, which signifies that the extension library and unit test match each other. - Continue debugging (you can press F5 for this). The debugging process continues until it completes successfully.