Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Is it Time to Toss frisby.js?

DZone's Guide to

Is it Time to Toss frisby.js?

Zone Leader John Vester provides analysis on his usage of frisby.js for REST API testing and why his team is focusing on using Newman now.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

Image titleNot too long ago, my company decided to use frisby.js for our REST API testing. The frisby.js framework is built on node.js and Jasmine and is intended to make testing API end-points "easy, fast, and fun" (according to the frisby.js web-site). Recently, the development and quality assurance (QA) staff got together to ask if it is time to toss frisby.js from our toolset.

Challenges We've Seen

While the web-site promises an easy, fast, and fun experience, our reality doesn't seem to use those adjectives.

The first challenge we faced is with the level of documentation provided. At a high level, the documentation provides some basic knowledge of how to use the framework. When attempting to locate more detailed examples, I found myself struggling, without even a strong presence on Stack Overflow to rely on. A secondary issue is the syntax which is different enough to provide a modest challenge to learn. A tertiary issue centered around our struggles with trying to debug frisby.js tests.

Another challenge I ran into was the need to nest a lot of child REST calls when testing a page in our application. In one example, I wanted to hit the API for the drop-downs menus with the same choices that are presented by the application. I am not a fan of hard-coding this type of information into the test. However, in order to do this, each API called had to be nested inside the prior call. See the example below:

frisby.create('API Test')
    .addHeader("Content-Type", "application/json")
    .addHeader("Accept", "application/json")
    .post(url + '/login', {
        username: username,
        password: password
    }, {
        json: true
    })
    .expectStatus(200)
    .afterJSON(function (res) {
        frisby.create('Getting Contract')
            .get(url + 'contracts/' + contractId)
            .expectStatus(200)
            .afterJSON(function (res) {
                contract = res;
                frisby.create('Getting State')
                    .get(url + 'states/' + stateId)
                    .expectStatus(200)
                    .afterJSON(function (res) {
                        state = res;
                        frisby.create('Getting Business Title')
                            .get(url + 'names/business_titles/' + businessTitleId)
                            .expectStatus(200)
                            .afterJSON(function (res) {
                                businessTitle = res;
                                frisby.create('Getting Other Stuf')
                                    .get(url + 'addresses/other_stuff/' + otherStuffId)
                                    .expectStatus(200)
                                    .afterJSON(function (oStuff) {
                                        otherStuff = oStuff;
                                        frisby.create('Getting Name Suffix')
                                            .get(url + 'names/suffixes/' + nameSuffixId)
                                            .expectStatus(200)
                                            .afterJSON(function (res) {
                                                nameSuffix = res;
                                                frisby.create('Finally performing API test here')
                                                    .post(url + '/contracts/something', {
                                                        'contract': {
                                                            'id': contract.id,
                                                            'rowVersion': contract.rowVersion
                                                        },
                                                        'firstName': 'FirstName',
                                                        'lastName': 'LastName',
                                                        'businessTitle': businessTitle,
                                                        'otherStuff': otherStuff,
                                                        'state': state,
                                                        'nameSuffix': nameSuffix,
                                                        'licenseState': state,
                                                        ...
                                                    }, {
                                                        json: true
                                                    })
                                                    .expectStatus(200)
                                                    .expectHeaderContains('content-type', 'application/json')
                                                    .expectJSONTypes(expectedJSONTypes)
                                                    .expectJSON({
                                                        'firstName': 'FirstName',
                                                        'lastName': 'LastName',
                                                        ...
                                                    })
                                            }).toss();
                                    }).toss();
                            }).toss();
                    }).toss();
            }).toss();
    }).toss();

I could not find a way around this (see first challenge above), but I wasn't a fan of starting my test logic at column 50.

The last challenge I ran into, which is not solely an issue with frisby.js, is the inability to roll-back transactions created as part of the tests. So, if my test performs a POST/PUT, after the test finishes, there is a new record in the database. Conversely, frameworks like JUnit do not commit records to the database. In our case, we implemented a "small database" concept, where we initialize a database to use for testing, then purge it after the test finishes. Calling a DELETE method wasn't always an option since our application does not have a requirement for delete functionality.

Where We Are Heading

Image title

Our QA Architect, after hearing our frustrations and performing some analysis, has recommended that we consider using Newman. For those who are not aware, Newman is a command-line companion tool for Postman. In our case, nearly every developer and QA member has been using Postman as a tool with our REST APIs. Newman has the ability to integrate collections within Postman and run the tests any time code is saved in our IDE (if desired).

So far, the change has been a positive experience. However, there are a significant amount of frisby.js tests to convert, which should put Newman through its paces to validate our decision.

Conclusion

In our case, we decided to toss frisby.js from our suite of test tools and focus on using Newman. Using frisby.js wasn't the easy, fast, and fun experience we were hoping to enjoy. I am certainly not saying our choice and direction is the one route everyone should take. In fact, I am sure there are others who could make a recommendation to leave Newman for frisby.js and cite similar issues with our current REST API testing framework. Instead, I wanted to provide a summary of our experiences with frisby.js and provide a summary of our current direction.

Have a really great day!

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
rest api ,testing ,web design and web development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}