Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
course-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT1901
course-material
Commits
68191efc
You need to sign in or sign up before continuing.
Commit
68191efc
authored
4 years ago
by
George Adrian Stoica
Browse files
Options
Downloads
Patches
Plain Diff
Add slides for lecture 10
parent
ee845746
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#85557
passed
4 years ago
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lectures/revealjs/10-unit-testing.adoc
+231
-0
231 additions, 0 deletions
lectures/revealjs/10-unit-testing.adoc
with
231 additions
and
0 deletions
lectures/revealjs/10-unit-testing.adoc
0 → 100644
+
231
−
0
View file @
68191efc
= Unit testing
:customcss: slides.css
:icons: font
:includedir: revealjs/includes/
:LECTURE_TOPIC: Unit testing
:LECTURE_NO: 10th Lecture
include::{includedir}header.adoc[]
[.smaller-80][.center-paragraph]
IT1901 Fall 2020 - {LECTURE_NO}
[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 know, 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 4
``` 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
== JUnit 5
``` java
import org.junit.jupiter.api.*;
public class FoobarTest {
@BeforeAll
public static void setUpClass() throws Exception {
// Code executed before the first test method
}
@BeforeEach
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
}
@AfterEach
public void tearDown() throws Exception {
// Code executed after each test
}
@AfterAll
public static void tearDownClass() throws Exception {
// Code executed after the last test method
}
}
```
== JUnit 4 vs JUnit 5
[.smaller-60]
[%header,cols=3*]
|===
|Element
|JUnit 4
|JUnit 5
|package
|org.junit.*
|org.junit.jupiter.api.*
|code before first test
|@BeforeClass
|@BeforeAll
|code before each test
|@Before
|@BeforeEach
|test
|@Test
|@Test
|code after each test
|@After
|@AfterEach
|code after last test
|@AfterClass
|@AfterAll
|===
== JUnit 4 vs JUnit 5 (2)
[.smaller-60]
[%header,cols=3*]
|===
|Element
|JUnit 4
|JUnit 5
|ignoring test
|@Ignore
|@Disabled
|assertions *statically* accessed with
|`Assert.assert`...
|`Assertions.assert`...
|assertion messsage position
|in the beginning of argument list
|in the end of argument list
|===
[background-color = "#124990"]
[color = "#fff6d5"]
== Testing in simpleexample1
[background-color = "#124990"]
[color = "#fff6d5"]
== Testing in todo-list example
include::{includedir}footer.adoc[]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment