Slide 1

Slide 1 text

SUPERCHARGE YOUR AUTOMATED TESTING

Slide 2

Slide 2 text

• Fundamentals • Automated testing playbook • Case study • Golden rules 05 Agenda

Slide 3

Slide 3 text

AUTOMATED TESTING FUNDAMENTALS

Slide 4

Slide 4 text

• Why write tests • Testing pyramid • Types of automated test 05 Fundamentals

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Why write automated tests? • Deliver faster and higher quality • Your product is always ready to deploy • Capture institutional knowledge in tests • Automation hugely improves productivity

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

05 The Testing Pyramid Slower Higher level Better QA Harder to debug Faster More specific Less useful for QA Better for debugging

Slide 9

Slide 9 text

The Testing Pyramid - Android • Android UI Tests, Real Servers • Android Tests, Real Servers • JVM/Robolectric Tests, Mock Data • Android Tests, Mock Data

Slide 10

Slide 10 text

Client Server View Presenter Data Access User Types of Automated Test

Slide 11

Slide 11 text

Client Server User Types of Automated Test Unit Test Unit Test Unit Test

Slide 12

Slide 12 text

Component Test Client Server User Types of Automated Test Component Test

Slide 13

Slide 13 text

Integration Test Client Server User Types of Automated Test

Slide 14

Slide 14 text

Black Box Test Client Server User Types of Automated Test

Slide 15

Slide 15 text

AUTOMATED TESTING PLAYBOOK

Slide 16

Slide 16 text

• Tedious • Slow • Necessary 05 Problem 1 – Manual QA Testing

Slide 17

Slide 17 text

Black Box Test Client Server User Black Box Tests

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

@Test public void testLoginSmokeTest() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown() .acceptTermsAndConditions(); }

Slide 20

Slide 20 text

@Test public void testLoginSmokeTest() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown() .acceptTermsAndConditions(); }

Slide 21

Slide 21 text

@Test public void testLoginSmokeTest() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown() .acceptTermsAndConditions(); }

Slide 22

Slide 22 text

@Test public void testLoginSmokeTest() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown() .acceptTermsAndConditions(); }

Slide 23

Slide 23 text

@Test public void testLoginSmokeTest() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown() .acceptTermsAndConditions(); }

Slide 24

Slide 24 text

Pros • Avoid tedious manual QA testing • Faster releases after code freeze • High confidence that basic features work Cons • Fail if your APIs/environment are flakey • Slow build/test cycle for developers • Hard to debug when something goes wrong 05 Black Box Tests

Slide 25

Slide 25 text

• Need to find bugs early • Tests need to be super fast 05 Problem 2 – Developers Need Tests Too

Slide 26

Slide 26 text

Unit Tests Client Server User Unit Test Unit Test Unit Test

Slide 27

Slide 27 text

• Static utilities 05 Unit Test Playbook

Slide 28

Slide 28 text

@Test public void testSafeCompareEqual() { assertThat(NumberUtils.safeCompare(null, null)).isEqualTo(0); assertThat(NumberUtils.safeCompare(21, 21)).isEqualTo(0); } @Test public void testSafeCompareLessThan() { // Right param is less than left param assertThat(NumberUtils.safeCompare(21, null)).isEqualTo(-1); assertThat(NumberUtils.safeCompare(23, 21)).isEqualTo(-1); } @Test public void testSafeCompareMoreThan() { // Left param is less than right param assertThat(NumberUtils.safeCompare(null, 21)).isEqualTo(1); assertThat(NumberUtils.safeCompare(21, 22)).isEqualTo(1); }

Slide 29

Slide 29 text

@Test public void testSafeCompareEqual() { assertThat(NumberUtils.safeCompare(null, null)).isEqualTo(0); assertThat(NumberUtils.safeCompare(21, 21)).isEqualTo(0); } @Test public void testSafeCompareLessThan() { // Right param is less than left param assertThat(NumberUtils.safeCompare(21, null)).isEqualTo(-1); assertThat(NumberUtils.safeCompare(23, 21)).isEqualTo(-1); } @Test public void testSafeCompareMoreThan() { // Left param is less than right param assertThat(NumberUtils.safeCompare(null, 21)).isEqualTo(1); assertThat(NumberUtils.safeCompare(21, 22)).isEqualTo(1); }

Slide 30

Slide 30 text

@Test public void testFormatAsCurrencyPositive() { assertThat(formatAsCurrency("0.01")).isEqualTo("$0.01"); assertThat(formatAsCurrency("3.45")).isEqualTo("$3.45"); assertThat(formatAsCurrency("3.5")).isEqualTo("$3.50"); assertThat(formatAsCurrency("22.22")).isEqualTo("$22.22"); assertThat(formatAsCurrency("333.33")).isEqualTo("$333.33"); assertThat(formatAsCurrency("4444.44")).isEqualTo("$4,444.44"); assertThat(formatAsCurrency("55555.55")).isEqualTo("$55,555.55"); }

Slide 31

Slide 31 text

@Test public void testFormatAsCurrencyPositive() { assertThat(formatAsCurrency("0.01")).isEqualTo("$0.01"); assertThat(formatAsCurrency("3.45")).isEqualTo("$3.45"); assertThat(formatAsCurrency("3.5")).isEqualTo("$3.50"); assertThat(formatAsCurrency("22.22")).isEqualTo("$22.22"); assertThat(formatAsCurrency("333.33")).isEqualTo("$333.33"); assertThat(formatAsCurrency("4444.44")).isEqualTo("$4,444.44"); assertThat(formatAsCurrency("55555.55")).isEqualTo("$55,555.55"); }

Slide 32

Slide 32 text

@Test public void testFormatAsCurrencyPositive() { assertThat(formatAsCurrency("0.01")).isEqualTo("$0.01"); assertThat(formatAsCurrency("3.45")).isEqualTo("$3.45"); assertThat(formatAsCurrency("3.5")).isEqualTo("$3.50"); assertThat(formatAsCurrency("22.22")).isEqualTo("$22.22"); assertThat(formatAsCurrency("333.33")).isEqualTo("$333.33"); assertThat(formatAsCurrency("4444.44")).isEqualTo("$4,444.44"); assertThat(formatAsCurrency("55555.55")).isEqualTo("$55,555.55"); }

Slide 33

Slide 33 text

@Test public void testDecrypt() { byte[] decryptedData = decrypt(ENCRYPTED_DATA); String decryptedText = new String(decryptedData); assertThat("expectedUnencryptedText").isEqualTo(decryptedText); }

Slide 34

Slide 34 text

• Static utilities • Edge cases 05 Unit Test Playbook

Slide 35

Slide 35 text

@Captor ArgumentCaptor exceptionCaptor; @Test public void testTransactionsErrorWithNullReferenceId() { TransactionsResponse event = new TransactionsResponse(new BaseError("error message")); fragment.receiveTransactions(event); assertThat(fragment.loadingMessage).isVisible(); assertThat(fragment.loadingMessage).hasText( "Unable to load transactions"); verify(analytics).trackError( "Unable to load transactions", "error message"); verify(loggingUtil).logHandledException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue().getMessage()) .isEqualTo("Unable to load transactions"); }

Slide 36

Slide 36 text

@Captor ArgumentCaptor exceptionCaptor; @Test public void testTransactionsErrorWithNullReferenceId() { TransactionsResponse event = new TransactionsResponse(new BaseError("error message")); fragment.receiveTransactions(event); assertThat(fragment.loadingMessage).isVisible(); assertThat(fragment.loadingMessage).hasText( "Unable to load transactions"); verify(analytics).trackError( "Unable to load transactions", "error message"); verify(loggingUtil).logHandledException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue().getMessage()) .isEqualTo("Unable to load transactions"); }

Slide 37

Slide 37 text

@Captor ArgumentCaptor exceptionCaptor; @Test public void testTransactionsErrorWithNullReferenceId() { TransactionsResponse event = new TransactionsResponse(new BaseError("error message")); fragment.receiveTransactions(event); assertThat(fragment.loadingMessage).isVisible(); assertThat(fragment.loadingMessage).hasText( "Unable to load transactions"); verify(analytics).trackError( "Unable to load transactions", "error message"); verify(loggingUtil).logHandledException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue().getMessage()) .isEqualTo("Unable to load transactions"); }

Slide 38

Slide 38 text

@Captor ArgumentCaptor exceptionCaptor; @Test public void testTransactionsErrorWithNullReferenceId() { TransactionsResponse event = new TransactionsResponse(new BaseError("error message")); fragment.receiveTransactions(event); assertThat(fragment.loadingMessage).isVisible(); assertThat(fragment.loadingMessage).hasText( "Unable to load transactions"); verify(analytics).trackError( "Unable to load transactions", "error message"); verify(loggingUtil).logHandledException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue().getMessage()) .isEqualTo("Unable to load transactions"); }

Slide 39

Slide 39 text

@Captor ArgumentCaptor exceptionCaptor; @Test public void testTransactionsErrorWithNullReferenceId() { TransactionsResponse event = new TransactionsResponse(new BaseError("error message")); fragment.receiveTransactions(event); assertThat(fragment.loadingMessage).isVisible(); assertThat(fragment.loadingMessage).hasText( "Unable to load transactions"); verify(analytics).trackError( "Unable to load transactions", "error message"); verify(loggingUtil).logHandledException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue().getMessage()) .isEqualTo("Unable to load transactions"); }

Slide 40

Slide 40 text

• Static utilities • Edge cases • Important features 05 Unit Test Playbook

Slide 41

Slide 41 text

@Test public void testSecureWindowFlagSet() { int FLAG_SECURE = WindowManager.LayoutParams.FLAG_SECURE; ShadowWindow shadowWindow = shadowOf(activity.getWindow()); assertThat(shadowWindow.getFlag(FLAG_SECURE)).isTrue(); }

Slide 42

Slide 42 text

• Static utilities • Edge cases • Important features • Collaboration 05 Unit Test Playbook

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

@Mock public CardControlsFeature feature; @Test public void testLockedCardFeatureOn() { when(feature.isCardLockEnabled()).thenReturn(true); assertThat(cardLock).isVisible(); assertThat(cardLock).hasText("Card is Locked"); assertThat(rewards).isGone(); } @Test public void testLockedCardFeatureOff() { when(feature.isCardLockEnabled()).thenReturn(false); assertThat(cardLock).isGone(); assertThat(rewards).isVisible(); }

Slide 45

Slide 45 text

@Mock public CardControlsFeature feature; @Test public void testLockedCardFeatureOn() { when(feature.isCardLockEnabled()).thenReturn(true); assertThat(cardLock).isVisible(); assertThat(cardLock).hasText(”This Card is Locked"); assertThat(rewards).isGone(); } @Test public void testLockedCardFeatureOff() { when(feature.isCardLockEnabled()).thenReturn(false); assertThat(cardLock).isGone(); assertThat(rewards).isVisible(); }

Slide 46

Slide 46 text

@Mock public CardControlsFeature feature; @Test public void testLockedCardFeatureOn() { when(feature.isCardLockEnabled()).thenReturn(true); assertThat(cardLock).isVisible(); assertThat(cardLock).hasText(”This Card is Locked"); assertThat(rewards).isGone(); } @Test public void testLockedCardFeatureOff() { when(feature.isCardLockEnabled()).thenReturn(false); assertThat(cardLock).isGone(); assertThat(rewards).isVisible(); }

Slide 47

Slide 47 text

@Mock public CardControlsFeature feature; @Test public void testLockedCardFeatureOn() { when(feature.isCardLockEnabled()).thenReturn(true); assertThat(cardLock).isVisible(); assertThat(cardLock).hasText(”This Card is Locked"); assertThat(rewards).isGone(); } @Test public void testLockedCardFeatureOff() { when(feature.isCardLockEnabled()).thenReturn(false); assertThat(cardLock).isGone(); assertThat(rewards).isVisible(); }

Slide 48

Slide 48 text

@Mock public CardControlsFeature feature; @Test public void testLockedCardFeatureOn() { when(feature.isCardLockEnabled()).thenReturn(true); assertThat(cardLock).isVisible(); assertThat(cardLock).hasText(”This Card is Locked"); assertThat(rewards).isGone(); } @Test public void testLockedCardFeatureOff() { when(feature.isCardLockEnabled()).thenReturn(false); assertThat(cardLock).isGone(); assertThat(rewards).isVisible(); }

Slide 49

Slide 49 text

Pros • Fast • Great for small components • Forces you to write clean, testable code Cons • Often need to be rewritten when refactoring components • Easy to miss things in the gaps between tests 05 Unit Tests

Slide 50

Slide 50 text

• Often don’t guarantee component behaves correctly as a whole • Tests are tightly coupled 05 Problem 3 – Unit Tests Can’t Do Everything

Slide 51

Slide 51 text

public class MyTwoAPICalls { private class Part1Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { bus.post(new Part2Request()); } } @Subscribe public void busListener(Part2Request event) { remote.part2(event).enqueue(new Part2Callback()); } private class Part2Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { // Do more stuff } } }

Slide 52

Slide 52 text

public class MyTwoAPICalls { private class Part1Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { bus.post(new Part2Request()); } } @Subscribe public void busListener(Part2Request event) { remote.part2(event).enqueue(new Part2Callback()); } private class Part2Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { // Do more stuff } } }

Slide 53

Slide 53 text

public class MyTwoAPICalls { private class Part1Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { bus.post(new Part2Request()); } } @Subscribe public void busListener(Part2Request event) { remote.part2(event).enqueue(new Part2Callback()); } private class Part2Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { // Do more stuff } } }

Slide 54

Slide 54 text

public class MyTwoAPICalls { private class Part1Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { bus.post(new Part2Request()); } } @Subscribe public void busListener(Part2Request event) { remote.part2(event).enqueue(new Part2Callback()); } private class Part2Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { // Do more stuff } } }

Slide 55

Slide 55 text

public class MyTwoAPICalls { private class Part1Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { bus.post(new Part2Request()); } } @Subscribe public void busListener(Part2Request event) { remote.part2(event).enqueue(new Part2Callback()); } private class Part2Callback { @Override public void onSuccessResponse(Call call, Response part1Response) { // Do more stuff } } }

Slide 56

Slide 56 text

Component Tests Client Server User Component Test

Slide 57

Slide 57 text

• Edge cases 05 Component Test Playbook

Slide 58

Slide 58 text

Example Component Client Server API Component Event Bus HTTP UI

Slide 59

Slide 59 text

Example Component Client Server API Component Event Bus Request UI

Slide 60

Slide 60 text

Example Component Client Server API Component Event Bus Request UI

Slide 61

Slide 61 text

Example Component Client Server API Component Event Bus HTTP Request UI

Slide 62

Slide 62 text

Example Component Client Server API Component Event Bus HTTP Response UI

Slide 63

Slide 63 text

Client Server API Component Event Bus Response UI Example Component

Slide 64

Slide 64 text

Client Server API Component Event Bus UI Component Test

Slide 65

Slide 65 text

Example Component Test Client API Component Event Bus Component Test UI Mocked Server

Slide 66

Slide 66 text

Example Component Test Client API Component Event Bus Component Test UI Mocked Server

Slide 67

Slide 67 text

• Edge cases 05 Component Test Playbook

Slide 68

Slide 68 text

@Test public void testServiceUnavailable503Html() { stubResponse(503, "service_unavailable_503.html"); bus.post(new Request()); assertBusEventReceived(); assertTrue(response.isError()); }

Slide 69

Slide 69 text

@Test public void testServiceUnavailable503Html() { stubResponse(503, "service_unavailable_503.html"); bus.post(new Request()); assertBusEventReceived(); assertTrue(response.isError()); }

Slide 70

Slide 70 text

@Test public void testServiceUnavailable503Html() { stubResponse(503, "service_unavailable_503.html"); bus.post(new Request()); assertBusEventReceived(); assertTrue(response.isError()); }

Slide 71

Slide 71 text

@Test public void testServiceUnavailable503Html() { stubResponse(503, "service_unavailable_503.html"); bus.post(new Request()); assertBusEventReceived(); assertTrue(response.isError()); }

Slide 72

Slide 72 text

@Test public void testServiceUnavailable503Html() { stubResponse(503, "service_unavailable_503.html"); bus.post(new Request()); assertBusEventReceived(); assertTrue(response.isError()); }

Slide 73

Slide 73 text

@Test public void testServiceUnavailable503Json() { stubResponse(503, "service_unavailable_503.json"); bus.post(new Request()); assertBusEventReceived(); assertEquals("SERVICE_UNAVAILABLE", response.getStatus()); assertEquals("We are undergoing system maintenance", response.getDescription()); }

Slide 74

Slide 74 text

@Test public void testServiceUnavailable503Json() { stubResponse(503, "service_unavailable_503.json"); bus.post(new Request()); assertBusEventReceived(); assertEquals("SERVICE_UNAVAILABLE", response.getStatus()); assertEquals("We are undergoing system maintenance", response.getDescription()); }

Slide 75

Slide 75 text

• Edge cases • Validate contracts 05 Component Test Playbook

Slide 76

Slide 76 text

@Test public void testGetTransactionsSuccess() { stubTransactions(200, "transactions_success.json"); bus.post(new TransactionsRequest()); assertBusEventReceived(); assertSuccessResponse(response); assertTrue(response.getTransactions().size() > 0); }

Slide 77

Slide 77 text

@Test public void testGetTransactionsSuccess() { stubTransactions(200, "transactions_success.json"); bus.post(new TransactionsRequest()); assertBusEventReceived(); assertSuccessResponse(response); assertTrue(response.getTransactions().size() > 0); }

Slide 78

Slide 78 text

Component UI Tests Component Test Client Server User

Slide 79

Slide 79 text

• Difficult to test UI flows 05 Component Test Playbook

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

@Test public void testActivateSingleCard() { stubberator.stubItAll(mockAccount); login(mockAccount); new ThirdPartyPayRobot() .assertActivateCardScreenShown() .activate() .assertActivationSuccessScreen() .gotIt(); }

Slide 82

Slide 82 text

@Test public void testActivateSingleCard() { stubberator.stubItAll(mockAccount); login(mockAccount); new ThirdPartyPayRobot() .assertActivateCardScreenShown() .activate() .assertActivationSuccessScreen() .gotIt(); }

Slide 83

Slide 83 text

@Test public void testActivateSingleCard() { stubberator.stubItAll(mockAccount); login(mockAccount); new ThirdPartyPayRobot() .assertActivateCardScreenShown() .activate() .assertActivationSuccessScreen() .gotIt(); }

Slide 84

Slide 84 text

@Test public void testActivateSingleCard() { stubberator.stubItAll(mockAccount); login(mockAccount); new ThirdPartyPayRobot() .assertActivateCardScreenShown() .activate() .assertActivationSuccessScreen() .gotIt(); }

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

• Difficult to test UI flows • Hermetic tests to avoid flakey tests 05 Component Test Playbook

Slide 88

Slide 88 text

@Test public void testLoginSuccess() { TestAccountModel testAccount = testAccountManager.get(TestAccountType.blackbox); new LoginAndFtuxRobot() .skipWelcomeScreen() .username(testAccount.username) .password(testAccount.password) .login() .assertTermsAndConditionsShown(); }

Slide 89

Slide 89 text

@Test public void testLoginSuccess() { stubberator.stubItAll(mockAccount); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot() .username("user") .password("pwd") .login() .assertTermsAndConditionsScreenShown(); }

Slide 90

Slide 90 text

@Test public void testLoginSuccess() { stubberator.stubItAll(mockAccount); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot() .username("user") .password("pwd") .login() .assertTermsAndConditionsScreenShown(); }

Slide 91

Slide 91 text

@Test public void testLoginSuccess() { stubberator.stubItAll(mockAccount); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot() .username("user") .password("pwd") .login() .assertTermsAndConditionsScreenShown(); }

Slide 92

Slide 92 text

@Test public void testLoginIncorrectUsernameOrPassword() { stubberator.stubItAll(mockAccount); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot(). .username("user") .password("pwd") .login() .assertTermsAndConditionsScreenShown(); }

Slide 93

Slide 93 text

@Test public void testLoginIncorrectUsernameOrPassword() { stubberator.stubItAll(mockAccount); stubFor(StubMappings.login().willReturn(aResponse() .withStatus(401).withBody(gson.toJson(ERROR_RESPONSE)))); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot(). .username("user") .password("pwd") .login() .assertTermsAndConditionsScreenShown(); }

Slide 94

Slide 94 text

@Test public void testLoginIncorrectUsernameOrPassword() { stubberator.stubItAll(mockAccount); stubFor(StubMappings.login().willReturn(aResponse() .withStatus(401).withBody(gson.toJson(ERROR_RESPONSE)))); activityRule.launchActivity( new Intent(applicationContext, SplashActivity.class)); new LoginAndFtuxRobot(). .username("user") .password("pwd") .login() .assertInvalidUsernameOrPassword(); }

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

Pros • Validate component correctness at its interfaces • No need to update tests when refactoring component internals • Component UI tests aren’t flakey • Screenshots work as documentation Cons • Slower than unit tests 05 Component & Component UI Tests

Slide 98

Slide 98 text

• Your project slips if you do API integration testing too late • Test environment issues 05 Problem 4 – APIs Are Hard

Slide 99

Slide 99 text

Integration Test Client Server User Integration Tests User

Slide 100

Slide 100 text

• Check the API works as expected 05 Integration Test Playbook

Slide 101

Slide 101 text

Component Test Client API Component Event Bus Component Test UI Mocked Server

Slide 102

Slide 102 text

Component Test -> Integration Test Client API Component Event Bus Integration Test UI Server

Slide 103

Slide 103 text

• Check the API works as expected 05 Integration Test Playbook

Slide 104

Slide 104 text

@Test public void testCardLockStatusUpdateSuccess() { Card card = loginAndGetCard(TestAccountType.card_lock_eligible); boolean wasCardOriginallyLocked = card.isCardLocked(); updateCardLockStatus(!wasCardOriginallyLocked, card); // Now change it back to the original lock status again updateCardLockStatus(wasCardOriginallyLocked, card); }

Slide 105

Slide 105 text

@Test public void testCardLockStatusUpdateSuccess() { Card card = loginAndGetCard(TestAccountType.card_lock_eligible); boolean wasCardOriginallyLocked = card.isCardLocked(); updateCardLockStatus(!wasCardOriginallyLocked, card); // Now change it back to the original lock status again updateCardLockStatus(wasCardOriginallyLocked, card); }

Slide 106

Slide 106 text

@Test public void testCardLockStatusUpdateSuccess() { Card card = loginAndGetCard(TestAccountType.card_lock_eligible); boolean wasCardOriginallyLocked = card.isCardLocked(); updateCardLockStatus(!wasCardOriginallyLocked, card); // Now change it back to the original lock status again updateCardLockStatus(wasCardOriginallyLocked, card); }

Slide 107

Slide 107 text

@Test public void testCardLockStatusUpdateSuccess() { Card card = loginAndGetCard(TestAccountType.card_lock_eligible); boolean wasCardOriginallyLocked = card.isCardLocked(); updateCardLockStatus(!wasCardOriginallyLocked, card); // Now change it back to the original lock status again updateCardLockStatus(wasCardOriginallyLocked, card); }

Slide 108

Slide 108 text

@Test public void testCardLockStatusUpdateSuccess() { Card card = loginAndGetCard(TestAccountType.card_lock_eligible); boolean wasCardOriginallyLocked = card.isCardLocked(); updateCardLockStatus(!wasCardOriginallyLocked, card); // Now change it back to the original lock status again updateCardLockStatus(wasCardOriginallyLocked, card); }

Slide 109

Slide 109 text

• Check the API works as expected • Add useful assertions 05 Integration Test Playbook

Slide 110

Slide 110 text

@Test public void testCardsSuccess() { loginAndGetCards(testAccount); assertSuccessResponse(response); List cards = response.getCards(); assertFalse("No cards were returned for " + testAccount, cards.isEmpty()); for (Card card : cards) { assertNotNull( "reference_id is missing on cards API, ” + ”transactions and receipt images will not be available", card.getReferenceId()); } }

Slide 111

Slide 111 text

@Test public void testCardsSuccess() { loginAndGetCards(testAccount); assertSuccessResponse(response); List cards = response.getCards(); assertFalse("No cards were returned for " + testAccount, cards.isEmpty()); for (Card card : cards) { assertNotNull( "reference_id is missing on cards API, ” + ”transactions and receipt images will not be available", card.getReferenceId()); } }

Slide 112

Slide 112 text

@Test public void testCardsSuccess() { loginAndGetCards(testAccount); assertSuccessResponse(response); List cards = response.getCards(); assertFalse("No cards were returned for " + testAccount, cards.isEmpty()); for (Card card : cards) { assertNotNull( "reference_id is missing on cards API, ” + ”transactions and receipt images will not be available", card.getReferenceId()); } }

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

• Check the API works as expected • Add useful assertions • Use them for environment monitoring! 05 Integration Test Playbook

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

Pros • Trivial to write if you have component tests • Automatically diagnose API issues • Easy to turn into API monitoring tools • Useful for validating older client versions still work Cons • Fail if your APIs/environment are flakey 05 Integration Tests

Slide 117

Slide 117 text

CASE STUDY WALLET

Slide 118

Slide 118 text

Capital One Wallet Git Commits Pull Request PR Merged Assemble APKs and Test APKs Integration Tests Component Tests Component UI Tests Blackbox Tests ✓ ✓ ✓ ✓ ✓ ✓ Component UI Tests Unit Tests Component Tests ✓ ✓ ✓ Unit Tests ✓

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

05 Our Testing Pyramid QA team Dev team

Slide 121

Slide 121 text

GOLDEN RULES

Slide 122

Slide 122 text

• Every bug needs an automated test (Production, QA, master) • Write tests at the same time as coding • Write a failing test before making it pass • Write tests as low in the testing pyramid as possible • Run tests before merging pull requests 05 Golden Rules

Slide 123

Slide 123 text

JOIN OUR TEAM

Slide 124

Slide 124 text

05 Capital One Wallet • Building a great app • Launch partner for FourSquare Pilgrim SDK • Top rated finance app by a US bank • First US bank with native Android contactless payments • Passionate about • Automated testing and continuous integration • Learning and sharing

Slide 125

Slide 125 text

THANK YOU