3

What I'm looking for in an answer

  • Concrete relevant(newer?) examples of why one choice is better than the other
  • OR, a concrete suggestion of why using a different language is the better choice over using Javascript to test the live API

I'm new to Angular and just started a job working on QA for a project with a front end written in Angular. I'm planning on writing e2e for the UI in Protractor with Jasmine. I need to write roughly equivalent e2e tests for the API, I know I don't want mocking tests (Unit tests will be written in Karma or in the C# back end directly, I'm still working that out). I want to hit the live endpoints.

My thought was to use Javascript for my testing, to keep the list of languages being used in the product short. I've narrowed down to using either Jasmine with FrisbyJS or Mocha and Chai. I want to choose something that will survive for the foreseeable future, but at the least the next 2 years.

Jasmine and FrisbyJS

Pros:

  • I'm using Jasmine already with Protractor/Karma
  • FrisbyJS seems easy enough to use once setup
  • Does do testing of live API endpoints easily
  • Jasmine is an industry standard and will survive long-term

Cons:

  • Frisby seems to have gone through a major rewrite and all tutorials I find are from <= 2015 and before this rewrite that now uses Jest instead of Jasmine-Node to run the tests and the documentation on the github page is just wrong in places and I'm having to figure out how to run things I don't even know how to use yet (I have no issue struggling through learning if it's the best choice though!)
  • Lack of newer examples on how to use the framework
  • Still in the middle of rewrite
  • Unsure of longevity

Mocha and Chai

Pros:

  • Seem to be a lot of newer tutorials
  • Does do testing of live API endpoints easily

Cons:

  • Not using Jasmine, so new testers will have to learn both Jasmine (which is being using with Protractor for UI) and Mocha (maybe this isn't a big deal)
  • Seems newer, so unsure of the longevity of the framework/module

Some Background Considerations

  • I've researched using PostMan or SoapUI for testing of live API (what's the term for this too please??) endpoints, but determined I'm going to have to code regardless, so I'd prefer to not introduce another language or have to pay for another service when I can make languages I have already work
  • I have a lot of experience using Java and TestNG to do live API and UI testing (with a custom wrapper library built around Selenium), so I know what it should look like in general
  • I'm hoping to reach out to someone with more experience in this with an Angular background as I am the QA expert at my position and I have no one here I can physically pester with questions.

I apologize if this is too much an opinion question. If there's another place I should post this please direct me and I'll remedy with a removal of this question.

1

I'm relatively new to the MEAN stack, so I had to answer this question for myself in the last 1-2 months. I chose Jasmine/Frisby.

Here is why:

  • As you say, there are many tutorials and examples for Mocha/Chai/chai-http, so while initially experimenting with Node/Express, Mocha/Chai/chai-http was my initial choice. And I liked the setup.

  • I then started learning Angular, where Jasmine is the default choice. Jasmine's syntax is quite similar to Mocha/Chai/expect, but not 100% identical. Which kind of bothered me.

  • When I went back to testing Node/Express, I needed to mock some objects. To add mock & spy capabilities to Mocha/Chai, you need to add Sinon to the mix.

  • Jasmine can mock and spy natively, but it needs Frisby for testing REST APIs. So the choice was between:

    1. Mocha/Chai/expect/chai-http/Sinon for testing the back-end and Jasmine for testing the front-end. Or,
    2. Jasmine/Frisby for the back-end and Jasmine for the front-end.

Choice (2) not only depends on fewer packages, but it also lets me use identical syntax for the front-end and back-end. Sounds like a winning combination to me :-)

2

1) If you're testing at the level of an http request your app's use of angular is almost certainly a non-factor. Angular would matter more were you testing at the browser level ("as a user" basically). When talking about http request level testing you're thinking more "as a system" and how it interacts with your api.

2) What're you're looking for is an appropriate testing stack for this type of testing. First you'll want a test framework/test runner, similar but not limited to jasmine, mocha, ava, etc. Second, you'll want a library designed for testing a rest api (like Frisby or certain Chain plugins that you mention) or additionally Supertest or any number of other test-focused rest clients. You could even use a client that isn't written primarily for testing and use your own assertions based on the outcome.

3) Pick a combination of test framework and specific http client that you like and run with it. At the end of the day they're going to do mostly the same thing and be extendable in similar ways. The most important part is your comfort with the combination of tools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.