-3

i have a sytem a that include system b and return the result. simple!.

concrete example an API, one controller that internally call another class then perform the operation.

route
--> controller 
-----> class 

I would do this a series of unit test for all piece the code then a series of functional test for the controller then a series of functional test for the class used in controller well!

my doubt is this for functional test of controller i test the behaviour a,b,c simil a black box input > controller > output.

but for functional test of the class used inner the controller i test the same behaviour a,b,c because the controller is a simple container that delegate a inner class.

in the end I will have the serie of functional test very very similar. from my point of view this is correct because for example the controller he could do the same things but do not use that inner class.

I try to explain better in pseudo code:

The architecture type is:

controller class 
   mehtodCallFromAPI 
     ... do someOtherThings..
     call otherclass->doSomething();

Functional of test controller on API

1 - test if after call API respond Http status code 201 
2 - test if after call API the db is change 
3 - test if after call API the status of system is changed related businessLogic 

Functional of test class inner controller on API

<strike>1 - test if after call API respond Http status code 201</strike>
2 - test if after call method class  the db is change 
3 - test if after call method class  the status of system is changed related businessLogic 

This is correct ?

  • Why do you feel the need to test the internal class? If the controller tests passes you know that the internal class is doing its job don't you? – Goyo Jul 28 '18 at 22:24
  • It's very difficult to tell what you're asking. What you're testing isn't clear. What you're expecting isn't clear. I suspect there is a good on topic question here but it needs more work. Please edit the question. – candied_orange Jul 29 '18 at 1:07
  • @candied_orange I try to better set the question – BruceStackOverFlow Jul 29 '18 at 7:02
  • @Goyo because in a large codebase, if I delete the test on the controller, the class remains without testing for example – BruceStackOverFlow Jul 29 '18 at 7:03
  • 1
    The only legitimate reason to delete the test for the controller would be if you also delete the controller, in which case you also would delete the helper. No? – Jörg W Mittag Jul 29 '18 at 9:21
0

Interpreting the various comments I can say that in this case. The best solution is create functional test only for the controller.

this i the key of discussion for me.

Then the helper is tested through the tests for those other parties, is it not?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.