Controllers = integration test?

as soon as I asked a similar question before. We have a forum system:

class ForumThread
{
    public function delete ($threadId)
    {
        Container::getPost()->deletePostsByThreadId ($threadId);
        Container::getSql()->sql ('DELETE FROM threads WHERE ID = '.$threadId);
    }
}

class Post
{
    public function deletePostsByThreadId ($threadId)
    {
        Container::getSql()->sql ('DELETE FROM posts WHERE THREAD_ID = '.$threadId);
    }
}

      

as you can see it gets the post and thread objects from the container, they can be replaced, mocked, etc. When I tested the device, I felt like something was missing: so its okay to check if the forum thread has actually been deleted - so too. This is what unittesting is for - but do they work well together ? If they work normally autonomously, this does not guarantee that they work well. If the two alloying elements are well made, they may not match. Enter your integration test here:

class Controller
{
    function controllerDelete()
    {
        Container::getForumThread()->delete ($_POST['ID']);
    }
}

      

I am assuming that I can check both SQL tables here. Is my theory okay? Because if the controller testing was unittest-like it wouldn't make sense, since controllers are usually the shortest classes (once I did the ForumThread :: delete test, the test controller :: controllerDelete would be the same

+3


source to share


1 answer


As you already know, Unit Tests mainly focus on the smallest testable part of the application. Therefore, if they pass, the level of your device is fine. Integration testing is another thing - modules are pooled and tested as a group. So on the bottom line:

Is my theory OK?



Yes. What you need to validate in controller testing at this level is the functionality, performance, and reliability that you have already placed in line with your application design and requirements.

+4


source







All Articles