Should I only test public interfaces in BDD? (in general, and in particular in Ruby)

I am reading the (beta) rspec book from prag progs as I am interested in behavioral testing of objects. From what I have learned so far (caution: after reading only 30 minutes), the main idea is that I want my object to behave as expected, “from the outside”, that is, in its output and in against other objects.

Is it true that I should just test my object with a black box to ensure the correct exit / interaction with other objects?

This may be completely wrong, but given that all attention is focused on how my object behaves in the system, it seems to be an ideology that could be accepted. If so, how do we focus on the implementation of the object? How to verify that my private method does what I want to do for all input types?

I believe this question may be valid for all types of testing? I'm still pretty new to TDD and BDD.

+5
source share
3 answers

If you want to better understand BDD, try to think about it without using the word test.

, ( , ). , . , ( mocks), .

, , . , , , .

, , . . , , . .

, , , , , , .

, !

+10

, .

- BDD, , TDD. , BDD , TDD, " ".

-, , unit test, ,   , , , . "" ".

+2

Yes, focus on the public functions of the class. Private methods are just part of the public function that you will be testing. This point is a bit controversial, but, in my opinion, this should be enough to test the public functionality of the class (everything else also violates the OOP principle).

+1
source

All Articles