jonh
jonh

Reputation: 242

AngularJS Protractor Tests - should E2E tests have fixtures?

There are ton of questions asking how to mock http responses in protractor tests. How to do this is not the question, should we do this is the question.

http://en.wikipedia.org/wiki/Test_fixture#Software

I've been a QA Engineer for over 4 years, and most of my automated test experience deals with both low level (unit) tests of controllers, models, etc and high level (integration) tests of full systems. In my ruby world experience, we used Capybara for integration tests along with blueprint and factorygirl (for different projects) to create mock database entries. This was our integration/E2E testing.

I've only recently moved to a javascript team using AngularJS. The original built-in testing framework (now deprecated) had a mock Backend module which seemed suitable for our needs. Protractor is now the standard. Only after protractor gained steamed, have I heard the backlash of using fixtures for E2E testing. Many posts are pointing out that E2E testing should be testing the full stack, so any backends should not be mocked and be accessible.

Should integration tests use fixtures, and why?

Upvotes: 8

Views: 2555

Answers (4)

Dmitri Zaitsev
Dmitri Zaitsev

Reputation: 14056

You are asking 2 questions - about the e2e tests and the integration tests. :)

The e2e test, at least in Angular's world, is testing your complete application as a real user can interact with it. This includes testing your backend request and response. However, if that runs slow and requires resources, it makes perfect sense to switch to a smaller (or even fake) version of your backend for testing.

The integration test is about a part of your code, and unit test is about individual units. Both times some or all dependencies can be mocked to isolate the tests.

So in all cases using fixtures or mocks can be useful.

See my answer here for more detailed discussion of use cases, advantages and limitations of Karma and Protractor.

Upvotes: 1

ben.tiberius.avery
ben.tiberius.avery

Reputation: 2354

I'm facing the same issue here with a personal code project. I'm using the MEAN stack, and my solution will be to:

  1. use Grunt to run the tests.
  2. before starting the Node server, use the mongoose fixtures to set up the Mongodb test db (https://github.com/powmedia/mongoose-fixtures)
  3. start the Node server with a parameter to make it use the test db.

You could do something like this approach if on a different stack, although Grunt is very helpful as a general job runner.

Upvotes: 0

bdavidxyz
bdavidxyz

Reputation: 2560

There is a vocabulary problem here. What is called "e2e" testing in the Angular world has nothing to do with end-to-end testing. It is an end-to-end of the UI part only, which means no e2e test at all. It is UI testing.

Gojko Adzic, in "spec by example" book, recommands to do functional, fixture-based testing "below the skin of the application", i.e. without the UI part.

To answer your question :

-Should UI tests have fixture? No, use mocks or stubs

-Should Backend tests have fixture ? Yes

Upvotes: 2

user1750709
user1750709

Reputation: 563

Yes we use ngMockE2E to mock the backend we then expose some helpers to window object so we can seed various mock data states. We also use sinon to force a specific time for testing date sensative UI so all new Date() calls returns what you want

Upvotes: 0

Related Questions