web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Unit test class in D365FO - Execute unit class with equals condition

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

Please refer to my previous posts to know the details about the following:

Model:  DaxologyTest

Project: CG_UnitTestCases

In this post, will create a test method in the class CGSampleDataTest  by name IdExistsTest that checks whether the required values are present for a record with Id value as "4" in SampleTable by confining to execute in the company DAX. Just before checking the data, inserting the record with Id value 4 as setup data during execution. Using method assertEquals on each field to verify the value.

Step 1: In the class declaration set the class to extend SysTestCase class and set the attribute SysTestCaseDataDependency to company DAX.

[SysTestCaseDataDependency("DAX")]
class CGSampleDataTest extends SysTestCase

Step 2: Created a test method by name IdExistsTest, added the attribute SysTestMethod and added code as shown below:

public void IdExistsTest()
{
SampleTable sampleTable;
boolean idExists;
int id = 4;
select firstonly Id, Name, DueDate
from sampleTable
where sampleTable.Id == int2Str(id);

this.assertEquals(sampleTable.Id, "4", "Id is same as expected");
this.assertEquals(sampleTable.Name, "D", "Name exists");
this.assertEquals(sampleTable.DueDate, (today() - 1), "Due date is not same");
}
Step 3: Overridden method "setUpTestCase" and included code to insert a record with Id value as 4 in SampleTable.
Note: Method "setupTestCase" will be called before any test methods are invoked.

public void setUpTestCase()
{
SampleTable sampleTable;

sampleTable.Id = int2Str(4);
sampleTable.DueDate = today();
sampleTable.Name = "D";
sampleTable.insert();
}

Step 4: Build the solution. Executed the test method with the help of Test Explorer by navigating to the path Test > Windows >  TestExplorer in Visual Studio.

Step 5: Launched the Test explorer window and selected  RunSelectedTests on choosing CGSampleDataTest.IdExistsTest.

Step 6: Executed the test method and had the  test result as passed.

Regards.

Chaitanya Golla

Comments

*This post is locked for comments