Created
May 9, 2017 22:48
-
-
Save segunfamisa/55808c1b6858b1b5ee8fb09e7986299d to your computer and use it in GitHub Desktop.
Gist describing a potential usecase for VisibileForTesting annotation https://developer.android.com/reference/android/support/annotation/VisibleForTesting.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Calculator { | |
private int a; | |
private int b; | |
public Calculator(int a, int b) { | |
this.a = a; | |
this.b = b; | |
} | |
public void sum() { | |
doSum(a,b); | |
} | |
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | |
protected int doSum(int a, int b) { | |
return a + b; | |
} | |
} | |
public class CalculatorTest { | |
@Test | |
public void testSum() { | |
// given a, b & calculator instance | |
int a = 1; | |
int b = 3; | |
Calculator calc = new Calculator(a,b); | |
// when we do sum | |
int sum = calc.doSum(a,b); | |
// then verify that sum is 4 | |
assertEquals(sum, 4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment