Skip to main content

Notifications

Announcements

No record found.

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

Hi,

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

Model:  DaxologyTest

Project: CG_UnitTestCases

In this post, I will create a test method in the class CGSampleDataTest  by name IdExistsTest that checks whether a record with Id value as "5" exists or not in SampleTable

Step 1: In the class declaration set the class to extend SysTestCase class.

class CGSampleDataTest extends SysTestCase
Step 2: Created a test method by name IdExistsTest, added the attribute SysTestMethod and added code as shown below:
class CGSampleDataTest extends SysTestCase
{
[SysTestMethod]
public void IdExistsTest()
{
SampleTable sampleTable;
boolean idExists;
int id = 5;

select firstonly RecId
from sampleTable
where sampleTable.Id == int2Str(id);

idExists = (sampleTable.RecId) ? (true) : (false);

this.assertFalse((idExists == false), strFmt("Record with value of Id as %1 doesn't exists in Sample Table", id));

}

}
Step 3: 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 4: Launched the Test explorer window and selected RunSelectedTests on choosing CGSampleDataTest.IdExistsTest.
Step 5: Executed the test method and had the test result as failed with the message.

Regards,

Chaitanya Golla

Comments

*This post is locked for comments