Inf1-OP
Bonus Lecture - JUnit, Lambdas and Streams Volker Seeker
School of Informatics
March 20, 2019
Inf1-OP Bonus Lecture - JUnit, Lambdas and Streams Volker Seeker - - PowerPoint PPT Presentation
Inf1-OP Bonus Lecture - JUnit, Lambdas and Streams Volker Seeker School of Informatics March 20, 2019 Automatic Testing with JUnit Test Driven Development Source: https://dzone.com/articles/what-is-refactoring Simple Calculator Calculator
Bonus Lecture - JUnit, Lambdas and Streams Volker Seeker
School of Informatics
March 20, 2019
Source: https://dzone.com/articles/what-is-refactoring
Calculator
+mul(int, int):int +add(int, int):int +incrementAll(int[], int):void
Implement a utility class with calculator functionality.
They have, however, a few drawbacks:
They have, however, a few drawbacks: ◮ Using console output to evaluate test results requires manual effort and is error prone for more complex tests
They have, however, a few drawbacks: ◮ Using console output to evaluate test results requires manual effort and is error prone for more complex tests → use assertions instead!
They have, however, a few drawbacks: ◮ Using console output to evaluate test results requires manual effort and is error prone for more complex tests → use assertions instead!
They have, however, a few drawbacks: ◮ Using console output to evaluate test results requires manual effort and is error prone for more complex tests → use assertions instead! ◮ tests are unorganised, no easy way to test only certain methods
They have, however, a few drawbacks: ◮ Using console output to evaluate test results requires manual effort and is error prone for more complex tests → use assertions instead! ◮ tests are unorganised, no easy way to test only certain methods → use a test framework instead!
Automatic Testing with JUnit ◮ Tests results are evaluated automatically
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features ◮ Tests can easily be excluded from shipped product
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features ◮ Tests can easily be excluded from shipped product ◮ Framework functionality provides advanced capabilities
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features ◮ Tests can easily be excluded from shipped product ◮ Framework functionality provides advanced capabilities
◮ @Before or @After methods are executed before and after each test to setup and clean up the test environment
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features ◮ Tests can easily be excluded from shipped product ◮ Framework functionality provides advanced capabilities
◮ @Before or @After methods are executed before and after each test to setup and clean up the test environment ◮ @Test(timeout = 1000) allows testing for execution duration
Automatic Testing with JUnit ◮ Tests results are evaluated automatically ◮ Tests are organised in a standard way ◮ Tests can be executed in isolation for only specific features ◮ Tests can easily be excluded from shipped product ◮ Framework functionality provides advanced capabilities
◮ @Before or @After methods are executed before and after each test to setup and clean up the test environment ◮ @Test(timeout = 1000) allows testing for execution duration ◮ etc.
Lambda expressions in Java ◮ A lambda expression is an anonymous function
Lambda expressions in Java ◮ A lambda expression is an anonymous function ◮ It can be called without an explicit identifier, i.e. method name
Lambda expressions in Java ◮ A lambda expression is an anonymous function ◮ It can be called without an explicit identifier, i.e. method name ◮ This makes it easy to pass them around as method arguments
Lambda expressions in Java ◮ A lambda expression is an anonymous function ◮ It can be called without an explicit identifier, i.e. method name ◮ This makes it easy to pass them around as method arguments ◮ They can be used in place of any Functional Interface such as Predicate
Lambda expressions in Java ◮ A lambda expression is an anonymous function ◮ It can be called without an explicit identifier, i.e. method name ◮ This makes it easy to pass them around as method arguments ◮ They can be used in place of any Functional Interface such as Predicate
◮ An interface with only a single abstract method
Lambda expressions in Java ◮ A lambda expression is an anonymous function ◮ It can be called without an explicit identifier, i.e. method name ◮ This makes it easy to pass them around as method arguments ◮ They can be used in place of any Functional Interface such as Predicate
◮ An interface with only a single abstract method ◮ see java.util.function package for a large collection of available