Second Edition Page: 2 Contributors Page: 2 About the author Page: 2 About the reviewers Page: 2 Preface Page: 5 Who this book is for Page: 5 What this book covers Page: 5 To get the most out of this book Page: 5 Download the example code files Page: 6 Get the color images Page: 6 Conventions used Page: 6 Get in touch Page: 6 Share Your Thoughts Page: 6 Section 1: Automated Testing – A General Overview Page: 7 Chapter 1: Introduction to Automated Testing Page: 8 Why automated testing? Page: 8 Why not? Page: 9 Why yes? Page: 9 Some more arguments Page: 10 Silver bullet? Page: 11 When to use automated testing? Page: 11 After go-live bug fixing Page: 11 Buggy code Page: 11 Frequently modified code Page: 11 Business-critical code being changed Page: 11 Refactoring existing code Page: 11 New feature development Page: 11 Microsoft updates Page: 12 What is automated testing? Page: 12 Some more notes on automated tests Page: 12 Summary Page: 12 Chapter 2: Test Automation and Test-Driven Development Page: 13 TA versus TDD Page: 13 What is TDD? Page: 13 Only two rules to the game Page: 13 TDD – the red-green-refactor mantra Page: 13 TDD – taking small steps Page: 14 TDD – the benefits Page: 14 TDD and Microsoft Dynamics 365 Business Central Page: 14 Is TDD in Business Central possible? Page: 14 Don't know how to start? Page: 15 TDD in Business Central – by example Page: 15 TDD – all the way? Page: 18 TDD – inside-out or outside-in Page: 18 Summary Page: 18 Further reading Page: 19 Section 2:Automated Testing in Microsoft Dynamics 365 Business Central Page: 20 Chapter 3: The Testability Framework Page: 21 Technical requirements Page: 21 The five pillars of the testability framework Page: 21 Pillar 1 – Test codeunits and test functions Page: 21 Pillar 2 – The asserterror keyword Page: 22 Pillar 3 – Handler functions Page: 22 Pillar 4 – Test runner and test isolation Page: 23 Pillar 5 – Test pages Page: 25 Summary Page: 26 Chapter 4: The Test Tools, Standard Tests, and Standard Test Libraries Page: 27 Technical requirements Page: 27 Test Tools Page: 27 Adding tests to a test suite Page: 27 Running the tests Page: 28 Standard tests Page: 29 Base Application tests Page: 29 Categorization by FEATURE Page: 30 Standard libraries Page: 30 Finding useful standard helper functions Page: 30 Some generic and very useful standard libraries Page: 31 Summary Page: 32 Section 3:Designing and Building Automated Tests for Microsoft Dynamics 365 Business Central Page: 33 Chapter 5: Test Plan and Test Design Page: 34 No plan, no test Page: 34 Setting up a test plan Page: 34 Break down your application or feature Page: 35 Test case design patterns Page: 35 Four-phase testing Page: 35 Acceptance Test-Driven Development Page: 35 A note on test verification Page: 36 Applying test case design patterns successfully Page: 36 Test data setup design patterns Page: 37 Test fixture, data agnostics, and prebuilt fixture Page: 37 Test fixture and test isolation Page: 38 Shared fixture implementation Page: 38 Fresh fixture implementation Page: 38 Applying test data setup design patterns successfully Page: 38 Using customer wish as test plan Page: 38 And what about unit and functional tests? Page: 39 Test case design pattern and unit tests Page: 40 Functional testing versus integration testing Page: 40 Summary Page: 40 Further reading Page: 40 Chapter 6: From Customer Wish to Test Automation – the Basics Page: 41 Technical requirements Page: 41 From customer wish to test automation Page: 41 Data model Page: 41 Business logic Page: 41 Converting our customer wish into a test plan and test design Page: 42 Test example 1 – a first headless test Page: 43 Customer wish Page: 43 Application code Page: 43 Test code Page: 43 Test execution Page: 46 Test example 2 – a first positive-negative test Page: 46 Test code steps Page: 46 Create a test codeunit Page: 46 Test execution Page: 47 Test example 3 – a first UI test Page: 47 Customer wish Page: 47 Test code Page: 48 Test execution Page: 49 Headless versus UI Page: 49 Summary Page: 49 Chapter 7: From Customer Wish to Test Automation – Next Level Page: 50 Technical requirements Page: 50 Sales documents, customer template, and warehouse shipment Page: 50 Test example 4 – how to set up a shared fixture Page: 50 Customer wish Page: 50 Application code Page: 51 Test Code Page: 51 Test execution Page: 52 Test example 5 – how to parameterize tests Page: 52 Customer wish Page: 52 Application code Page: 52 Test code Page: 53 Test execution Page: 54 A missing scenario? Page: 54 Test example 6 – how to hand over data to UI handlers Page: 55 Customer wish Page: 55 Test code Page: 55 Test execution Page: 56 Summary Page: 56 Chapter 8: From Customer Wish to Test Automation – the TDD way Page: 57 Technical requirements Page: 57 TDD and our test examples Page: 57 Test example 7 – how to refactor your code Page: 57 Smell of duplication 1 Page: 58 Smell of duplication 2 Page: 58 Some more duplications? Page: 59 Refactoring application code, not covered by tests yet Page: 59 Test example 8 – how to test a report Page: 59 Customer wish Page: 59 Step 1 – Take a test from the test list and write the test code Page: 59 Step 2 – Compile test code yielding red as application code is not yet there Page: 60 Step 3 – Add just enough application code Page: 60 Step 4 – Run test seeing it probably fail Page: 60 Step 3 bis – Add just enough application code Page: 60 Step 4 bis – Run test seeing it probably fail Page: 61 Step 5 – Adjust the application code just enough to make it pass Page: 61 Step 6 – Refactor your code and rerun the test to prove all code is still well Page: 61 Test the test Page: 61 Test example 9 – how to test with permissions Page: 62 Step 1 – Take a test from the test list and write the test code Page: 62 Step 2 – Compile test code yielding red as application code is not yet there, and Step 3 – Add just enough application code Page: 63 Step 4 – Run the test seeing it probably fail Page: 63 Step 5 – Adjust application code just enough to make it pass, and Step 6 – Refactor your code and rerun the test to prove all code is still well Page: 63 Step 7 – Move to the next test on the list and repeat from Step 1 Page: 63 Continue the red-green-refactor mantra Page: 63 Some notes on testing permissions and the version of Business Central Page: 64 Summary Page: 65 Section 4:Integrating Automated Tests in Your Daily Development Practice Page: 66 Chapter 9: How to Integrate Test Automation in Daily Development Practice Page: 67 Technical requirements Page: 67 Casting the customer wish into ATDD scenarios Page: 67 ATDD.TestScriptor Page: 67 Learning and improving by taking small steps Page: 70 Making the test tool, and some more, your friend Page: 70 Extending the test tool Page: 70 AL Test Runner Page: 71 Code Coverage Page: 71 Maintaining your test code Page: 72 Organizing your extensions Page: 73 Integrating with the daily build system Page: 73 Using pipelines Page: 73 Or not using pipelines Page: 74 Summary Page: 74 Chapter 10: Getting Business Central Standard Tests Working on Your Code Page: 76 Technical requirements Page: 76 Why use the standard tests? Page: 76 Executing standard tests against your code Page: 76 Executing Tests-VAT Page: 77 What does this tell us? Page: 77 Only selecting tests from Tests-VAT Page: 77 Running tests using pipelines Page: 78 Fixing failing standard tests Page: 78 Attacking the error Page: 78 Fixing the error Page: 79 Running the failing tests again Page: 80 Disabling failing tests Page: 80 Syntax of DisabledTests.json Page: 80 It's all about data Page: 80 Executing and fixing Tests-Fixed Asset Page: 80 Running tests using pipelines Page: 81 Is it all really about data? Page: 81 Summary Page: 81 Section 5:Advanced Topics Page: 82 Chapter 11: How to Construct Complex Scenarios Page: 83 Technical requirements Page: 83 What makes a scenario complex? Page: 83 Data setup Page: 83 Verification Page: 84 End-to-end code execution path Page: 85 Dependencies on other systems Page: 86 Composing complex scenarios Page: 86 Finding common ground – steps 1, 2, 3, and 4 Page: 86 Deconstructing your scenario – steps 1, 2, 3, and 4 Page: 86 Using flowcharts – steps 1 and 3 Page: 86 Using Code Coverage – steps 1 and 3 Page: 87 Using standard helper functions – steps 5, 6, and 7 Page: 87 Creating reusable parts Page: 87 Test example 10 – how to construct an extensive scenario Page: 87 Customer wish Page: 87 Application code Page: 88 Test code Page: 88 Test execution Page: 90 Summary Page: 90 Chapter 12: Writing Testable Code Page: 91 Technical requirements Page: 91 What is testable code? Page: 91 How to make your code testable? Page: 91 Coding techniques Page: 92 Some notes on refactoring your code so it is testable Page: 95 Test example 11 – how to unit test event subscribers' logic Page: 95 Customer wish Page: 95 Application code Page: 95 Test code Page: 96 Test execution Page: 96 Summary Page: 96 Further reading Page: 97 Chapter 13: Testing Incoming and Outgoing Calls Page: 98 Technical requirements Page: 98 Testing incoming calls Page: 98 Technical challenges Page: 98 Examples of standard API tests Page: 100 Testing outgoing calls Page: 100 Test Doubles Page: 100 Replacing a server with a test double – dependency injection Page: 101 Some more notes on mock and mocking Page: 101 Examples of standard tests with test doubles replacing external components Page: 101 Test example 12 – testing incoming calls: Lookup Value API Page: 102 Application code Page: 102 Test scenarios Page: 102 Test Code – [SCENARIO #0200] Get lookup value Page: 102 Test Code – [SCENARIO #0202] Modify lookup value Page: 103 Test preparation Page: 104 Test execution Page: 104 Test example 13 – VAT Registration No. validation Page: 104 Application code Page: 104 Test code Page: 106 Test execution Page: 108 Summary Page: 108 Section 6:Appendix Page: 109 Appendix: Getting Up and Running with Business Central, VS Code, and the GitHub Project Page: 110 Setting up your Business Central environment Page: 110 Setting up Business Central from a product DVD Page: 110 Setting up Business Central in a container Page: 110 The GitHub repository Page: 111 Structure of the GitHub repository Page: 111 Chapter 02 Page: 111 Chapter 03 Page: 111 Excel Sheets Page: 111 Chapter 06 (LookupValue Extension) Page: 111 Chapter 07 (LookupValue Extension) Page: 112 Chapter 08 (LookupValue Extension) Page: 112 Chapter 09 (LookupValue Extension) Page: 112 Chapter 10 (LookupValue Extension) Page: 112 Chapter 11 (LookupValue Extension) Page: 112 Chapter 12 (LookupValue Extension) Page: 112 Chapter 13 (LookupValue Extension) Page: 112 Scripts Page: 112 Chapter 13 (VAT Registration No. Validation) Page: 112 LookupValue Extension Page: 112 Graphics Page: 112 Setting up VS Code Page: 112 VS Code project Page: 112 Notes on the AL code Page: 114 Prefix or suffix Page: 114 Word wrap Page: 114 Why subscribe? Page: 115 Other Books You May Enjoy Page: 115 Packt is searching for authors like you Page: 115 Share Your Thoughts Page: 115
Description: