0

I was at the point where I felt familiar with feature and unit tests in Laravel. But recently I created a new project and discovered Laravel Dusk. After its installation there now also is a Browser directory where I can put my tests in. But now I'm confused, what is the difference between a feature and a browser test? For example where would I put tests like

a_visitor_can_signup()
the_index_page_shows()
the_contact_form_validates()
..

Is browser behavior (interaction) a typical browser test? And would request-like tests like testing endpoints for a HTTP status 200 to ensure nothing is broken at that point be feature tests?

Ben Fransen
  • 10,884
  • 18
  • 76
  • 129

2 Answers2

3

A feature test would be a test, which tests a feature product may have asked for while a browser behavior test would test a specific action.

Feature Test: User can sign up.
Browser Behavior Test: When user clicks the button it submits the form.

Basically, the feature test is the end-to-end test. While the browser behavior test is a unit or integration test testing a single behavior.

In general, you want to have unit tests—each of which test a single behavior. One main reason being maintainability.

For example, if testing a javascript form, you may have behavioral javascript tests like the following:

describe("form#user-profile", function(){
  context("when a click event is triggered", function(){
    describe("`foo` is called with arguments a, b and c", function(){
       expect(foo).to.be.calledWith(a,b,c)
    })
  })
})

Which will read out as "form#user-profile, when a click event is triggered, foo is called with arguments a, b and c." This in essence is a unit test which tests a "browser behavior"

References

Mocha

Chai

Sinon

pygeek
  • 7,356
  • 1
  • 20
  • 41
0

I would summarize like this: If there is javascript involve in the test, use laravel dusk (browser test). If there is none, stick to feature test.

Apit John Ismail
  • 2,047
  • 20
  • 19