0

I'm trying to do an end-to-end smoke test for a one page app, and stuck with the following:

  • The app just runs as a bunch of HTML pages, and has no server side code (I'm running Apache locally to serve the pages).

  • The API calls are to /api/blah and I currently have an alias in my httpd.conf that redirects the /api/blah call to the proper server API (www.example.com/api/blah).

  • The API has an SSO requirement, so I want to avoid calling the actual API during functional testing.

I've got cucumber setup locally, with watir-webdriver handling the browser control. I've got a few tests running with the intial state, but would love to mock out the calls to the API with some dummy JSON I have stored with the project.

The tests will be eventually run on a TeamCity CI server.

I tried using WebMock and FakeWeb, but they're looking for serverside calls - so the ajax calls from the app are never hitting something they can intercept.

I've also looked into maybe firing up the server with jsTestDriver, then mocking it out there, but can't get the two to connect.

Are there any solutions for this out there, or has anyone had this problem and solved it reliably?

4

1 回答 1

1

There are several ways you could solve this.

  1. You could start a little HTTP server process serving your JSON fixtures alongside Cucumber and shut it down when the feature suite has finished loading. This could be written in Ruby/Node.js/whatever you like.

    You'll probably want to make the API base URI configurable so that it interacts with this little test server when automated by Cucumber but calls the real thing in production.

  2. Stub XMLHttpRequest (given that's what you're using to make API calls) and return the fixtures from there.

I would go for #1: make the base URI configurable instead of that forged "/api/blah" path and serve whatever you want in your specs through some basic HTTP server.

于 2012-09-17T08:08:47.613 回答