/canine

Canine is a simple series of webpages used to demonstrate the howling success of the Hound testing tool, especially when coupled with property-based testing strategies.

Primary LanguageElixir

Canine

Canine is a simple series of webpages used to demonstrate the howling success of the Hound testing tool.

Whatever you call it, UI testing/End-to-End Testing/End-to-User Testing/Acceptance Testing--it is often an intensely manual and time-consuming process. Hound carries some of the load through browser automation. Browser automations means that I can automate my user interactions — clicks, fill inputs, file uploads, selecting options, radio buttons, etc. I use this app to demonstrate an overview of Hound and it’s helpers, as well as an example of how Hound tests saved me days of manual end-user testing.

Bone Simple Creation

Create a simple Phoenix called Canine.

> mix phx.new canine --no-ecto

Add Hound as a dependency in mix.exs.

{:hound, "~> 1.0"}

Hound requires a webdriver for browser automation. We will use selenium. Install and run:

> brew install selenium-server-standalone
> selenium-server

Start Hound in test/test_helpers.exs. Add this above ExUnit.start()

Application.ensure_all_started(:hound)

In config/dev.exs add:

config :canine, region: System.get_env("REGION")

In config/test.exs add:

config :hound, browser: "chrome"
config :canine, region: System.get_env("REGION")

. . . and set server to true:

config :canine, CanineWeb.Endpoint,
  http: [port: 4001],
  server: true

Start the Phoenix server

  • install dependencies with mix deps.get
  • install Node.js dependencies with cd assets && npm install
  • start Phoenix endpoint with a REGION value from the list ["northeast", "midwest", "south", "west"]
    • elixir: REGION=midwest mix phx.server
    • interactive elixir: REGION=midwest iex -S mix phx.server
  • visit localhost:4000 from your browser.

Run tests (in this demo app, Hound is used as a part of ExUnit tests)

mix test

Lab-ra-cadabra!

The acceptance tests live in test/canine_web/acceptance/ and use test/support/acceptance_case.exs, an ExUnit.CaseTemplate.

- test/
  - canine_web/
    - acceptance/
      - form_test.exs
      - region_test.exs
      - welcome_test.exs
  - support/
    - acceptance_case.ex
  - test_helper.exs

Simple welcome_test.exs

Complex region_test.exs

More Complex form_test.exs

Notes on Metadata

To highlight Hound's Metadata, Canine uses a Plug called Regionalize for set regional vernacular. If this were a real app, this value would be part of an authentication process, but since this is a demo app for testing purposes, we aren't going to worry about the prod environment. We will use Application.get_env("REGION").

MIX_ENV=dev: In the dev environment, Application.get_env("REGION") is from an entry in config/dev.exs that uses System.get_evn("REGION") to grab the "REGION" value from the shell. If a "REGION" is not found, the user is sent to a non-functional signup page.

MIX_ENV=test: In the test environment, Application.get_env("REGION") is from Hound's metadata. Metadata parameters are set like this:

Hound.start_session(metadata: %{region: "northeast"})

If the metadata is not found, the test session will fail and alert you with an error.

** (RuntimeError) could not find a session for process #PID<X.XXX.X>

Go Fetch!