Software Testing and Validation Overview

S
W
E
 
4
3
4
S
O
F
T
W
A
R
E
 
T
E
S
T
I
N
G
 
A
N
D
 
V
A
L
I
D
A
T
I
O
N
L
A
B
3
 
 
J
U
N
I
T
1
SWE 
434
 
Lab
L
A
B
 
A
G
E
N
D
A
2
M
o
r
e
 
E
x
a
m
p
l
e
s
 
a
n
d
 
P
r
a
c
t
i
c
e
SWE 
434
 
Lab
U
N
I
T
 
T
E
S
T
I
N
G
R
e
q
u
i
r
e
d
 
I
n
p
u
t
 
a
n
d
 
E
x
p
e
c
t
e
d
 
O
u
t
p
u
t
.
3
U
n
i
t
I
n
p
u
t
O
u
t
p
u
t
SWE 
434
 
Lab
T
E
S
T
 
C
A
S
E
 
V
E
R
D
I
C
T
4
A
 
v
e
r
d
i
c
t
 
i
s
 
t
h
e
 
d
e
c
l
a
r
e
d
 
r
e
s
u
l
t
 
o
f
 
e
x
e
c
u
t
i
n
g
 
a
 
s
i
n
g
l
e
 
t
e
s
t
.
We 
can get the verdict after the assertion
 
statement
P
a
s
s
:
t
h
e
 
t
e
s
t
 
c
a
s
e
 
a
c
h
i
e
v
e
d
 
i
t
s
 
i
n
t
e
n
d
e
d
 
p
u
r
p
o
s
e
,
 
a
n
d
 
t
h
e
software under test performed as
 
expected.
F
a
i
l
:
t
h
e
 
t
e
s
t
 
c
a
s
e
 
a
c
h
i
e
v
e
d
 
i
t
s
 
i
n
t
e
n
d
e
d
 
p
u
r
p
o
s
e
,
 
b
u
t
 
t
h
e
s
o
f
t
w
a
r
e
 
u
n
d
e
r
 
t
e
s
t
 
d
i
d
 
n
o
t
 
p
e
r
f
o
r
m
 
a
s
 
e
x
p
e
c
t
e
d
.
E
r
r
o
r
:
t
h
e
 
t
e
s
t
 
c
a
s
e
 
d
i
d
 
n
o
t
 
a
c
h
i
e
v
e
 
i
t
s
 
i
n
t
e
n
d
e
d
 
p
u
r
p
o
s
e
.
Potential
 
reasons:
An unexpected event occurred during the test
 
case.
The test case could not be set up
 
properly
SWE 
434
 
Lab
J
U
N
I
T
 
M
E
T
H
O
D
S
a
s
s
e
r
t
A
r
r
a
y
E
q
u
a
l
s
(
)
Test 
whether two arrays are equal to each 
other. 
In other
words, if the two arrays contain the same number of
elements, and if all 
the 
elements in 
the 
array are equal
 
to
each
 
other.
a
s
s
e
r
t
T
r
u
e
(
)
 
+
 
a
s
s
e
r
t
F
a
l
s
e
(
)
The 
assertTrue() 
and assertFalse() methods tests a
 
single
expression to see if its 
value 
is either true, or
 
false.
a
s
s
e
r
t
N
u
l
l
(
)
 
+
 
a
s
s
e
r
t
N
o
t
N
u
l
l
(
)
The assertNull() and assertNotNull() methods test a
 
single
variable to see if it is null or not
 
null
5
SWE 
434
 
Lab
E
X
A
M
P
L
E
6
SWE 
434
 
Lab
Add parameter to 
@Test 
annotation, indicating that a particular
 
class
of exception is expected to 
occur 
during the
 
test
Useful for simple cases, but it has its
 
limits:
you can't test the value of the message in the exception, or
 
the
state of a domain object after the exception has been
 
thrown.
7
E
X
C
E
P
T
I
O
N
 
I
N
 
J
U
N
I
T
SWE 
434
 
Lab
Catch exception, and use 
fail( ) 
if not
 
thrown:
Try{
M
e
t
hod
T
oBe
T
es
t
ed
()
fail(“Message”)
}
Catch(ExceptionType
 
E){
}
8
E
X
C
E
P
T
I
O
N
 
I
N
 
J
U
N
I
T
SWE 
434
 
Lab
E
X
A
M
P
L
E
9
SWE 
434
 
Lab
S
E
T
U
P
 
A
N
D
 
T
E
A
R
D
O
W
N
For a collection of tests for a particular class, there are often some
repeated tasks that must be done prior to each test case or 
after
the end of each use
 
cases:
Set up
 
connection
Database
Clean
 
up
Reset
 
data
Ensures resources are released, test system is in known state for
next test case,
 
etc.
Since a test case failure ends execution of a test method at
 
that
point, code to clean up cannot be at the end of the
 
method.
1
0
SWE 
434
 
Lab
Setup:
Use 
the 
@Before 
annotation on a method containing code
 
to
run before each test
 
case.
Teardown:
Use 
the 
@After 
annotation on a method containing code to
 
run
after 
each test
 
case.
These 
methods 
will run even if exceptions are thrown in
 
the
test case or an assertion
 
fails.
1
1
S
E
T
U
P
 
A
N
D
 
T
E
A
R
D
O
W
N
SWE 
434
 
Lab
Setup
 
Once:
Use the 
@BeforeClass 
to run a method once only for the entire
test class, before any of the tests are executed, and prior to
 
any
@Before
 
method(s)
Teardown
 
Once:
Use the 
@AfterClass 
annotation to run after all test case
 
methods
in the class have been executed, and after any @After
 
methods
Useful for starting servers, opening communications, etc. that
 
are
time-consuming to close and 
re-open 
for each
 
test.
1
2
S
E
T
U
P
 
A
N
D
 
T
E
A
R
D
O
W
N
 
O
N
C
E
SWE 
434
 
Lab
1
3
S
E
T
U
P
 
A
N
D
 
T
E
A
R
D
O
W
N
SWE 
434
 
Lab
Slide Note
Embed
Share

In this comprehensive guide, we delve into various aspects of software testing, including JUnit testing, test cases, verdicts, and exception handling in JUnit. Explore examples, methods, and best practices to enhance your understanding of software testing and validation processes.

  • Software Testing
  • Validation
  • JUnit
  • Test Cases
  • Exception Handling

Uploaded on Sep 17, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. SWE SWE 434 SOFTWARE SOFTWARE TESTING 434 TESTING AND AND VALIDATION VALIDATION LAB3 LAB3 JUNIT JUNIT 1 SWE 434Lab

  2. LAB LAB AGENDA AGENDA More Examples and Practice 2 SWE 434Lab

  3. UNIT UNIT TESTING TESTING Required Input and Expected Output. Input Output Unit 3 SWE 434Lab

  4. TEST TEST CASE CASE VERDICT VERDICT A verdict is the declared result of executing a singletest. We can get the verdict after the assertion statement Pass: the test case achieved its intended purpose, andthe software under test performed asexpected. Fail: the test case achieved its intended purpose,but the software under test did not perform asexpected. Error: the test case did not achieve its intended purpose. Potential reasons: An unexpected event occurred during the testcase. The test case could not be set upproperly 4 SWE 434Lab

  5. JUNIT JUNIT METHODS METHODS assertArrayEquals() Test whether two arrays are equal to each other. In other words, if the two arrays contain the same number of elements, and if all the elements in the array are equalto each other. assertTrue() + assertFalse() The assertTrue() and assertFalse() methods tests asingle expression to see if its value is either true, orfalse. assertNull() + assertNotNull() The assertNull() and assertNotNull() methods test asingle variable to see if it is null or notnull 5 SWE 434Lab

  6. E EXAM XAMP PL LE E 6 SWE 434Lab

  7. EXCEPTION EXCEPTION IN IN JUNIT JUNIT Add parameter to @Test annotation, indicating that a particular class of exception is expected to occur during the test Useful for simple cases, but it has its limits: you can't test the value of the message in the exception, or the state of a domain object after the exception has been thrown. 7 SWE 434Lab

  8. EXCEPTION EXCEPTION IN IN JUNIT JUNIT Catch exception, and use fail( ) if not thrown: Try{ MethodToBeTested() fail( Message ) } Catch(ExceptionType E){ } 8 SWE 434Lab

  9. E EXAM XAMP PL LE E 9 SWE 434Lab

  10. SETUP AND SETUP AND TEARDOWN For a collection of tests for a particular class, there are often some repeated tasks that must be done prior to each test case or after the end of each use cases: Set up connection Database Clean up Reset data TEARDOWN Ensures resources are released, test system is in known state for next test case, etc. Since a test case failure ends execution of a test method at that point, code to clean up cannot be at the end of the method. 10 SWE 434Lab

  11. SETUP AND SETUP AND TEARDOWN TEARDOWN Setup: Use the @Before annotation on a method containing codeto run before each test case. Teardown: Use the @After annotation on a method containing code to run after each test case. These methods will run even if exceptions are thrown inthe test case or an assertionfails. 11 SWE 434Lab

  12. SETUP AND SETUP AND TEARDOWN TEARDOWN ONCE ONCE Setup Once: Use the @BeforeClass to run a method once only for the entire test class, before any of the tests are executed, and prior to any @Before method(s) Teardown Once: Use the @AfterClass annotation to run after all test case methods in the class have been executed, and after any @After methods Useful for starting servers, opening communications, etc. that are time-consuming to close and re-open for each test. 12 SWE 434Lab

  13. SETUP AND SETUP AND TEARDOWN TEARDOWN 13 SWE 434Lab

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#