Slide 1

Slide 1 text

Intro to Unit Test and Metrics By: Maikel Chandika ([email protected]) Medan, 28 July 2018.

Slide 2

Slide 2 text

Maikel Chandika, S.Kom, OCA  ICT Manager and Lead Java Developer at Waruna Group  Java Ecosystem and OSS Enthusiast  Website: https://mkdika.com  GitHub: mkdika 2

Slide 3

Slide 3 text

Todays Topics A Little Bite to Software Testing Java Testing Framework & Libs Unit Test Metrics & Demo To go further 3

Slide 4

Slide 4 text

Why Need Unit Test? 4

Slide 5

Slide 5 text

Software Testing Path Software Testing Developer Test Unit Test Integration Test Users Test End-to-End Test 5

Slide 6

Slide 6 text

Test Pyramid 6

Slide 7

Slide 7 text

Test Framework & Lib in Java  Testing Framework: JUnit, TestNG, JBehave  Mock Lib: Mockito, PowerMock, EasyMock  Parameterized Test Lib: JUnitParams  Equality Test Lib: Hamcrest  Integration Test Lib: Maven Failsafe, REST Assured, DBUnit 7

Slide 8

Slide 8 text

Unit Test Metric & Analysist Lib  Built System & Test env: Maven, Gradle  Code Coverage Lib: Jacoco, Cobertura  Mutation Test Lib: PIT  Load Test Tools: JMeter, Gatling  End-to-End/ Acceptance Test Tools: Cucumber 8

Slide 9

Slide 9 text

Test Metrics – Unit Test 9 Focus on single class/unit. Assertions and expectation.

Slide 10

Slide 10 text

Test Metrics – Coverage Test “A measure used to describe the degree to which the source code of a program is executed when a particular test suite runs.” 10

Slide 11

Slide 11 text

Test Metrics – Coverage Test? Percentage of our code call (statement, branch, path) from test environment. Not say anything about quality of our test. 11

Slide 12

Slide 12 text

Test Metrics – Coverage Test? 12

Slide 13

Slide 13 text

Test Metrics – Mutation Test 13 “Test how good are your Unit Test.” Add mutation (errors) to the code and check if unit test failed (fault seeding). Effectiveness of test is gauged by ratio of survived and killed mutations.

Slide 14

Slide 14 text

Test Metrics – Mutation Test? 14 Very CPU demanding & time consuming process. Will slow down review life cycle if run in every single commit.

Slide 15

Slide 15 text

What Next?  Unit test best practice  Mock Test  Integration Test  Test-driven Development (TDD)  Behavior-driven Development (BDD)  Automatic Static Code Analysis ex: Findbugs 15 Cucumber BDD Example

Slide 16

Slide 16 text

Other PL Unit Test Framework & Libs  PHP  Unit test & coverage: PHPUnit  Mutation test: Humbug  .NET  Unit test & coverage: MS Test, Nunit  Mutation test: VisualMutator, NinjaTurtle  Ruby  Unit test & coverage: RSpec  Mutation test: Mutant-RSpec  Python  Unit test & coverage: unittest, coverage  Mutation test: MutPy 16

Slide 17

Slide 17 text

Summary – Unit Test Metrics Coverage Test Numbers of code call from test environment (unit test). Mutation Test Test the quality of Unit Test. 17

Slide 18

Slide 18 text

Q & A 18

Slide 19

Slide 19 text

To Go Further 19 Practical Unit Testing with Junit and Mockito By: Tomek Kaczanowski

Slide 20

Slide 20 text

THANK YOU 20