white-box

When is it appropriate to bypass encapsulation in unit tests?

一笑奈何 提交于 2019-12-17 18:58:42
问题 I've recently become aware of powermock's Whitebox functionality. (In summary, it allows you to directly test private methods or modify private members directly from unit tests--while keeping them private!) I know that there are some frames of thought that frown upon unit testing anything other than visible methods, but darn it, sometimes you just want a simple test to ensure a deep level helper method is doing what it is supposed to do...without going through what could be huge overhead to

Should I use “glass box” testing when it leads to *fewer* tests?

混江龙づ霸主 提交于 2019-12-10 17:44:26
问题 For example, I'm writing tests against a CsvReader. It's a simple class that enumerates and splits rows of text. Its only raison d'être is ignoring commas within quotes. It's less than a page. By "black box" testing the class, I've checked things like What if the file doesn't exist? What if I don't have permission on the file? What if the file has non-Windows line-breaks? But in fact, all of these things are the StreamReader's business. My class works without doing anything about these cases.

Is it possible to mock a single method in an already existing object?

感情迁移 提交于 2019-12-07 13:33:21
问题 For an integration test, I need to mock a specific method in a java service client without destroying the rest of the information in it. It has no self-constructor, so a solution like this is out of the question: private DBClient mockClient = new DBClient(alreadyExistingClient){ @Override void deleteItem(Item i){ //my stuff goes here } }; Is there a way to mock the deleteItem method such that the credentials, endpoints, etc... are preserved in an existing DBClient object? edit: mockito is not

Is it possible to mock a single method in an already existing object?

夙愿已清 提交于 2019-12-06 03:24:21
For an integration test, I need to mock a specific method in a java service client without destroying the rest of the information in it. It has no self-constructor, so a solution like this is out of the question: private DBClient mockClient = new DBClient(alreadyExistingClient){ @Override void deleteItem(Item i){ //my stuff goes here } }; Is there a way to mock the deleteItem method such that the credentials, endpoints, etc... are preserved in an existing DBClient object? edit: mockito is not available for use in this case cahen You can use a Dynamic Proxy to intercept any method invocation

Unit testing, Black-box testing and white box testing [closed]

≯℡__Kan透↙ 提交于 2019-12-03 15:44:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago . What is Unit testing, Black-box testing and White-Box testing? I googled but all the explanation I found was very technical. Can anyone answer this question in a simple way with an appropriate example? 回答1: In black box testing , you don't care how the internals of the thing

When is it appropriate to bypass encapsulation in unit tests?

二次信任 提交于 2019-11-28 09:23:56
I've recently become aware of powermock's Whitebox functionality. (In summary, it allows you to directly test private methods or modify private members directly from unit tests--while keeping them private!) I know that there are some frames of thought that frown upon unit testing anything other than visible methods, but darn it, sometimes you just want a simple test to ensure a deep level helper method is doing what it is supposed to do...without going through what could be huge overhead to prepare the parameters and mocks needed for the parent methods to filter down to your method..and then

PHPUnit: Doing assertions on non-public variables

风格不统一 提交于 2019-11-27 22:45:14
Suppose I have a class with a private property and associated public getter and setter. I want to test with PHPUnit that the property gets the correct value after the setter has been used or that the getter returns the correct property. Of course I can test the setter by using the getter to see that the object is storing the correct value, and vice versa for testing the getter. However, this doesn't guarantee that the private property is the one being set. Say I had the following class. I created a property, getter and setter. But I made a typo in the property name, so the getter and the

Black box vs White box Testing

非 Y 不嫁゛ 提交于 2019-11-27 10:14:43
Which type of testing would you say should be the emphasis (for testers/QAs), and why? A quick set of definitions from wikipedia: Black box testing takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure. White box testing uses an internal perspective of the system to design test cases based on internal structure. It requires programming skills to identify all

PHPUnit: Doing assertions on non-public variables

别等时光非礼了梦想. 提交于 2019-11-26 23:12:22
问题 Suppose I have a class with a private property and associated public getter and setter. I want to test with PHPUnit that the property gets the correct value after the setter has been used or that the getter returns the correct property. Of course I can test the setter by using the getter to see that the object is storing the correct value, and vice versa for testing the getter. However, this doesn't guarantee that the private property is the one being set. Say I had the following class. I

Should black box or white box testing be the emphasis for testers?

非 Y 不嫁゛ 提交于 2019-11-26 15:04:18
问题 Which type of testing would you say should be the emphasis (for testers/QAs), and why? A quick set of definitions from wikipedia: Black box testing takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure. White box testing uses an internal perspective of the