ATF – Database View to summarize information about Test Suits, Tests and Test Steps

Recently I was asked for providing report with summary information about configured tests.
I’ve created a Database View to have it ready for the future requests (I’m expecting that sooner or later I’ll be asked again for the same).
The scheme is very simple:

The update set with this Database View:
Download

How to start with TDD in ServiceNow

This time I would like to present how to create very first unit test and adapt TDD for creating scripts in ServiceNow.
I’m going to create two very simple script includes: Course and Student.
The course will be implemented three methods:
– addStudent
– getStudent
– removeStudent

Continue reading How to start with TDD in ServiceNow

How to test Standard Change by Automated Test Framework – part 2

Problem with testing Read Only fields

Once you are ready to test Standard Change by using guide described here: How to test Standard Change by Automated Test Framework you’ll soon discover that ATF doesn’t check Read Only Fields correctly.

To avoid this problem you have to set default value for Standard Change Template version. To do this you need add the following code to the Server Side Script prepared in previous post.

var grV = new GlideRecord('sys_dictionary');
grV.addQuery('name', 'change_request');
grV.addQuery('element', 'std_change_producer_version');
grV.query();
    
grV.next();
grV.default_value='923504cc47410200e90d87e8dee490e2';
grV.update();

In effect ATF will test Standard Change created from template and properly check read only fields.

How to test Standard Change by Automated Test Framework

If you try to test standard change by using automated test framework you’ll soon find out that there is no easy way to test this type of change. Because during test execution you can’t open a page which allows you to select standard change:

You can add a new record by out of the box test step ‘Open a New Form’ but it creates default type of change (OOTB it’s Normal Change).

A workaround for this is changing the default value for change type during test execution. So before opening a new form add server side test step: ‘Run Server Side Script’.

And finally by the following query you can change the default value for change type:

(function() {
    var gr = new GlideRecord('sys_dictionary');
    gr.addQuery('name', 'change_request');
    gr.addQuery('element', 'type');
    gr.query();

    gr.next();
    gr.default_value = 'standard';
    gr.update();    
})();