If turn_twizzles
, push_buttons
, and move_mountain
are public and called by other code, then I think it's important to refactor your tests to test these functions individually.
Unfortunately after your refactor you have a problem: to unit test do_everything
you need to be able to mock turn_twizzles
, push_buttons
, and move_mountain
. Writing tests for do_everything
without mocking the dependencies will be an integration test--not necessarily a bad thing depending on your test plan, but there won't be much benefit because you're already testing the three smaller functions individually. This may be the right time for you to redesign this component and collaborate with other objects to do all the work of do_everything
.
If turn_twizzles
, push_buttons
, and move_mountain
are not called externally, they should be marked private, and I wouldn't recommend testing them separately from do_everything
. This is because from an outside-looking-in perspective, do_everything
would be the smallest unit (because the others are inaccessible). Also see this answer about breaking up methods using private methods.
private
keyword in a programming language is just one of many ways of restricting access to a piece of code. – marstato Nov 19 '17 at 01:41do_everything
and a test should never be concerned about the correctness of the subjects dependencies. But whether the dependencies need tests themselves is another story. I disagree withIf a class is so big and convoluted that testing against the public interface is not sufficient to help you find bugs
. More often than not a very small public interface is desireable (e.g. when writing a library) but at the same time, it makes sense to split the task up and both keep all code for the task close together. – marstato Nov 19 '17 at 17:34