Nika Kurashvili
Nika Kurashvili

Reputation: 6472

is controller testing functional testing?

I am really interested in different aspects of testing. I hope you can really read this and just give me your ideas if you have experience with this. Let's break down.

Fact 1: It's said that when we write a test from user perspective(going to uri, and getting results and if user sees the correct result, then test is right). They say this is called functional testing.

Sum up 1: So turns out when we write tests for controller, it's always functional as we must make the request to endpoint and observe the result. SO writing tests for controllers are always functional tests. Is that right?

==========================================================================

Fact 2: So, Integration testing is not controller testing. Let's imagine we have some functions (not controller functions) in our app. For example in our helper classes or models. and we want to test those functions like integration testing. So we won't mock anything and just test it.

Sum up 2: So, integration testing can be done on functions that are not controller functions, are written on other places(where request doesn't need to be done) and they must use external dependencies. By external dependencies, anything can be thought (such as file,database or another class itself) . Is that right?

==========================================================================

Sum up 3: what if I have just an api and instead of returning views, I return json and status codes from controllers. If i write test for controllers, it will still be called functional tests. right?

Upvotes: 2

Views: 651

Answers (1)

James Wilson
James Wilson

Reputation: 1636

Interesting question. I believe it depends on how you test the controller. Let's start with a couple of definitions of different types of testing. These definitions broadly follow your two facts.

Let's take the example of an e-commerce platform and the Controller for a checkout.

Controller - unit testing

This is where we have to consider the controller in isolation. So we want to mock the request from the user. For example, if you are using the Spring Framework you can make use of the library to mock http requests.

Controller - integration testing

To be an integration test we need to consider the interaction of two parts of the system. In our shopping basket example, we could mock the http request as above but test the interaction between the shopping basket and the checkout code.

Controller - functional testing

For functional testing, we need to consider the end to end scenario of the user clicking on the UI and using the shopping basket.

In summary, if you are testing your controller using something that is mocking the HTTP request then it is most likely unit or integration testing. If you are testing the controller using selenium or a user clicking on a UI then it is most likely functional testing.

Upvotes: 2

Related Questions