What is the best practice for a regression test that wants to know about encapsulated information?

by Wallace Brown   Last Updated May 07, 2018 20:05 PM

Suppose you have two classes: Alpha, and Bravo.

Alpha has a Bravo class with no getter (e.g. not publicly visible).
Bravo has a String named charlie (and a method to Get that String).

Let's say you have set up a test that constructs a new Alpha class. At the end of this test, you want to assert that bravo.getCharlie() is equal to some expected String. How should the test get access to this String?

Should we add a getBravo() method to Alpha just because this test seems to need it?

assertEquals("expectedString", alpha.getBravo().getCharlie());

Should we continue hiding Bravo but add a getter for Charlie inside of Alpha?

assertEquals("expectedString", alpha.getCharlie());

(where alpha.getCharlie() is just a way of writing alpha.getBravo().getCharlie() without making that Bravo getter public)

Any other options?



Related Questions


Testing properties with private setters

Updated April 29, 2016 08:02 AM

What is IBM's CUPRIMDS?

Updated February 18, 2017 10:05 AM

What does stubbing mean in programming?

Updated March 03, 2017 13:05 PM

Integration tests, but how much?

Updated February 28, 2017 08:05 AM

i want a postman's counterpart for mobile developers

Updated December 05, 2017 07:05 AM