diff --git a/lectures/revealjs/06-testing-quality.adoc b/lectures/revealjs/06-testing-quality.adoc new file mode 100644 index 0000000000000000000000000000000000000000..8be6f2448ad458cb5cd675c12eb6255525b91776 --- /dev/null +++ b/lectures/revealjs/06-testing-quality.adoc @@ -0,0 +1,291 @@ += Testing and code quality +:customcss: slides.css +:icons: font +:includedir: includes/ +:LECTURE_TOPIC: Testing and code quality +:LECTURE_NO: 6th Lecture + +include::{includedir}header.adoc[] + +[.smaller-80][.center-paragraph] +IT1901 Fall 2023 - {LECTURE_NO} + +[background-color = "#124990"] +[color = "#fff6d5"] +== Overview +[.smaller-80] +- Administrative issues +- Code quality + testing + +[background-color = "#124990"] +[color = "#fff6d5"] +== Administrative issues + +== Administrative issues + +* Individual assignment 1 +* Group work + + +== Individual assignment 1 + +* deadline today - 11.09.2023 18:00 +* about 80% submitted +* information about retake will be available after we check the exercises + + +== Group work + +- contact your team mates and start working on the group contract +- group contract deadline - 14.09.2023 18:00 +- work on 1st group assignment +** find a suitable project +** use gitlab to manage and track your project +** deadline - 21.09.2023 18:00 + +[background-color = "#124990"] +[color = "#fff6d5"] +== Code quality + + +== Code quality + +- automated tests +- coding standards and consistent formatting +- check for higher level types of errors (bug patterns) +- +++ + + + +[background-color = "#124990"] +[color = "#fff6d5"] +== Testing + + + +== Testing + +[%step] +- is an important part of software development +- a way to ensure software quality +- automated testing allows to develop new features with a minimal effort to check if the software still works as expected +- testing frameworks + +== Testing (2) + +[%step] +- design +- implement +- write automated tests +- run tests +- we do not test just for now, we write tests to keep running them during project life cycle + +== Testing (3) + +[%step] +- design tests +- implement the test +- provide inputs +- run the tests +- provide expected outputs +- check if the result we get matches what we expect +- produce a manageable output that the developer can consult + +== Testing (3) + +- design tests +- implement the test +- provide inputs +- *run the tests* +- provide expected outputs +- *check if the result we get matches what we expect* +- *produce a manageable output that the developer can consult* + + +[background-color = "#124990"] +[color = "#fff6d5"] +== JUnit + + +== JUnit + +- Is a Java unit testing framework. +- provides the means to automate test +- allows to eliminate redundant testing tasks + + +== JUnit (2) + +``` java +import org.junit.*; + +public class FoobarTest { + @BeforeClass + public static void setUpClass() throws Exception { + // Code executed before the first test method + } + + @Before + public void setUp() throws Exception { + // Code executed before each test + } + + @Test + public void testOneThing() { + // Code that tests one thing + } + + @Test + public void testAnotherThing() { + // Code that tests another thing + } + + @Test + public void testSomethingElse() { + // Code that tests something else + } + + @After + public void tearDown() throws Exception { + // Code executed after each test + } + + @AfterClass + public static void tearDownClass() throws Exception { + // Code executed after the last test method + } +} +``` + +[.smaller-40] +https://en.wikipedia.org/wiki/JUnit +https://junit.org/junit5/docs/current/user-guide/ + + + +[background-color = "#124990"] +[color = "#fff6d5"] +== TestFX + +== TestFX + +- testing for JavaFx applications +- provides robots for UI testing +- support for JUnit + +[.smaller-40] +https://github.com/TestFX/TestFX + + +[background-color = "#124990"] +[color = "#fff6d5"] +== Mockito + + +== Mockito + +- mocking is a technique to test functionality in isolation +- mock objects simulate real objects +- return dummy values corresponding to the input given at creation +- Mockito uses reflection features in Java to create the mock objects + +[.smaller-40] +https://site.mockito.org/ + + +[background-color = "#124990"] +[color = "#fff6d5"] +== Jacoco + +== JaCoCo (1) + +- Java Code Coverage (JaCoCo) +- popular tool for measuring code coverage in Java projects +- measures several metrics + +== Jacoco (2) + +- tool for assessing code coverage +- does not need modifying code +- can produce a report in html format +- integrates with a number a tools including Gradle + +[.smaller-40] +https://www.jacoco.org/ + + + +== JaCoCo metrics + +- Instructions +- Branches (exception handling is excluded) +- Cyclomatic Complexity - "According to McCabe1996 cyclomatic complexity is the minimum number of paths that can, in (linear) combination, generate all possible paths through a method." +- Lines +- Methods +- Classes + +[.smaller-40] +https://www.jacoco.org/jacoco/trunk/doc/counters.html + +== Tools for automatic code checking + +- Checkstyle (https://checkstyle.sourceforge.io/index.html) +- Spotbugs (https://spotbugs.readthedocs.io/en/latest/index.html) +- Pmd (https://pmd.github.io) +- Sonarcube (https://www.sonarqube.org/) +- ... + +== Checkstyle + +- static analysis +- finds errors like +** references to variables with undefined value +** variables that are never used +** syntax and coding standards violations +** dead code blocks + +== Checkstyle (2) + +- naming conventions +- line length +- whitespace +- Javadoc comments +- annotations + +== Checkstyle (3) + +- can be configured to use a certain set of checks +- extendable - one can write own checks +- plugins for IDEs + +[background-color = "#124990"] +[color = "#fff6d5"] +== Checkstyle examples + + +== Spotbugs + +- checks bytecode and not the source +- looks for "bug patterns" +- example: + +``` +An apparent infinite loop (IL_INFINITE_LOOP) +This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception). +``` + +== Spotbugs (2) + +- extendable +- plugins for Maven Gradle Ant +- Eclipse IDE integration + +[background-color = "#124990"] +[color = "#fff6d5"] +== Spotbugs examples + +[background-color = "#124990"] +[color = "#fff6d5"] +== Summary + +include::{includedir}footer.adoc[] \ No newline at end of file