It is not entirely clear whether it is necessary to completely cover everything with tests, even those methods that can not break precisely because of their simplicity, or still only logical sections need to be tested.

Here is an example method:

private void continuousFromStopPoint(int i) { switch (i) { case 0: startAppReg(); break; case 1: startGCMReg(); break; case 2: startAppRegUpdate(); break; } } 

Depending on the value, it calls one method or another. And I don’t even have an idea how to test it.

Or this method seems to be more interesting:

 private boolean isWasFinished(JSONObject jsonObject) { boolean wasFinished = false; try { if (jsonObject != null) { wasFinished = jsonObject.getBoolean(WAS_FINISHED); } } catch (JSONException e) { e.printStackTrace(); } return wasFinished; } 

Here it is already possible to check the return value, but then again, what to check it for when I don't care which value returns. If true code will do one, if false then another. What to check?

Tell me how to figure it out?

  • In the first method, as an option, you can test / check the processing of the passed values: -1, 0, 100. Do I understand correctly that when receiving such values, the method should not do anything? - lospejos
  • @lospejos is generally correct. All that does not apply to 0, 1, 2 should be ignored ... And for example, can you write how this test should look like? - Aleksey Timoshchenko
  • Why are you testing private methods? Do not do it this way. As if public methods that use private work correctly for you, then private work correctly. - temq
  • @temq oo, by the way, I also wanted to find out, because when I generate a test class, he suggests adding only public methods. But then the logic is not completely clear, because there can be such when a class uses a bunch of private methods that are called from onCreate() and have logic in them, so why not test them? So onCreate() -> privat() (слоТная Π»ΠΎΠ³ΠΈΠΊΠ°) -> privat() (слоТная Π»ΠΎΠ³ΠΈΠΊΠ°) -> privat() (слоТная Π»ΠΎΠ³ΠΈΠΊΠ°) such a class should be left without tests, right? - Aleksey Timoshchenko
  • 2
    Well, the result is somewhere displayed, not in the empty, they thresh. You can make complex logic in a separate class with a public method that returns the result and test it. It’s generally difficult to test when a business is. Logic is sewn into Activity / Fragment. If you use the same mvp, then the logic is easy to test separately from ui. And it is worth considering that you can not just take and test any code. You need to learn how to write code that you can then easily test. - temq

0