From ce7d0fa3fd5d14bc4c39d84cee2d6b2a820e676f Mon Sep 17 00:00:00 2001
From: Adrian Stoica <stoica@ntnu.no>
Date: Wed, 18 Sep 2024 13:25:26 +0200
Subject: [PATCH] doc: update slides for the 5th lecture

---
 lectures/revealjs/05-testing.adoc | 337 ++++++++++++++++++++++++++++++
 1 file changed, 337 insertions(+)
 create mode 100644 lectures/revealjs/05-testing.adoc

diff --git a/lectures/revealjs/05-testing.adoc b/lectures/revealjs/05-testing.adoc
new file mode 100644
index 0000000..cc94704
--- /dev/null
+++ b/lectures/revealjs/05-testing.adoc
@@ -0,0 +1,337 @@
+= Code Quality and Testing
+:customcss: slides.css
+:icons: font
+:includedir: includes/
+:LECTURE_TOPIC: Code Quality and Testing
+:LECTURE_NO: 5th Lecture
+
+include::{includedir}header.adoc[]
+
+[.smaller-80][.center-paragraph]
+IT1901 Fall 2024 - {LECTURE_NO}
+
+[background-color = "#124990"]
+[color = "#fff6d5"]
+== Overview
+
+[.smaller-80]
+- Administrative issues
+- 2nd Group Exercise
+- Code Quality
+** Testing
+- Summary
+
+[background-color = "#124990"]
+[color = "#fff6d5"]
+== Administrative issues
+
+== Administrative issues
+
+* Mandatory Individual Assignment
+* Group work
+
+
+== Mandatory Individual Assignment
+
+* deadline was on 12.09.2024
+* the majority submitted 
+* information about retake will be available after we check the exercises
+
+
+== Group work
+
+- prepare for delivery
+- you submit the link to repo and the commit hash to evaluate
+- report any group drop out cases - exercises are designed to work for 3-4 people
+- we take into account the reduced numbers when grading
+- test your deliverable in Eclipse Che
+
+
+== Approaching Deadlines
+
+- Torsdag, 19. september / 23:59 
+** 1st group deliverable
+
+- Torsdag, 19. september / 23:59 
+** group contract
+
+
+[background-color = "#124990"]
+[color = "#fff6d5"]
+== 2nd Group Exercise
+
+
+
+
+
+[background-color = "#124990"]
+[color = "#fff6d5"]
+== Code quality
+
+== Code quality
+
+- testing
+ ** automated tests
+ ** +++
+- coding standards and consistent formatting
+- check for higher level types of errors (bug patterns)
+- +++
+
+
+[background-color = "#124990"]
+[color = "#fff6d5"]
+== Testing
+
+== Crowdstrike incident 2024
+
+* largest IT outage in history
+* several billion USD in losses
+* affected roughly 8.5 million systems
+* bad test practices - happy path, no compatibility
+* bad deployment practices
+
+== Knight Capital Group (2012)
+
+* technician forgot to copy the new version on one of the servers
+* new version repurposed a flag that trigerred the olde version to send orders indefinitely
+* 440 million USD lost
+* lack of thorough regression testing
+
+== Therac-25 - mid 80s
+
+* radiation treatment cancer patients
+* software issues - wrong dose
+* caused 6 accidents, killed 3 patients
+* bad design and development practices
+* unfeasible to test properly and automate tests
+
+
+
+== 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
-- 
GitLab