Search code examples
playframeworkfunctional-testing

What is the aim of FunctionalTest in PlayFramework?


I'm writing tests for my project, and after the Unit Tests, I'm now writing FunctionalTest.

But between the aim of Functional vs Selenium test, I'm a bit lost.

Is the functional test are just here to test if, whatever I sent to any page (mostly in POST), it should return what I expect (200, 302, 404, 500), or is there more ? (like test if the page returned is the one I expect (like "Login page"? or this test should be in Selenium?)

Because so far, my F tests are just a bunch of functions with an assertStatus for each, and I feel it's a bit useless. I believe I can do more, but don't know why.

What do you test in your Functional tests?


Solution

  • To answer your question, it is probably easier to look at all three types of tests alongside each other.

    Unit Test - To test an individual unit of code. For example, if I had an Item class, which made up part of a eCommerce site, I would have a number of Unit tests to test that the Item class functioned as expected. This may include a test to prove that the search function returns items that match specific criteria.

    Functional Test - To test that when individual units are brought together, they work together as expected. For example, for the search function to work, we would expect to send a specific RESTful URL to search for an item, which would return a specific response. It would use our controller, and model classes to execute the code and achieve the complete function.

    Acceptance Test - Also known as Selenium tests are much larger set of tests. These test a scenario that a user may run through, that may cover many functional tests, that in turn may encompass many unit tests. These are concerned more with processing a user journey or a scenario, rather than individual pieces of functionality.

    As for the types of asserts that are used in FunctionalTests, I have also used assertFalse and assertTrue by using the getContent method on the response object.