0% found this document useful (0 votes)
41 views

Chap 5

This document introduces unit testing and the JUnit framework. It discusses using JUnit to write separate test classes and methods to test individual classes and methods in an application. Some limitations of JUnit testing are that it does not ensure all code is tested, is not well-suited for testing user interfaces or entire applications, and can be complex for testing private methods. The document provides examples of how to structure unit tests in JUnit.

Uploaded by

Nasis Dereje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Chap 5

This document introduces unit testing and the JUnit framework. It discusses using JUnit to write separate test classes and methods to test individual classes and methods in an application. Some limitations of JUnit testing are that it does not ensure all code is tested, is not well-suited for testing user interfaces or entire applications, and can be complex for testing private methods. The document provides examples of how to structure unit tests in JUnit.

Uploaded by

Nasis Dereje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Intoduction to Unit Testing

Using JUnit to structure Unit Testing

SE-2030 1
Dr. Mark L. Hornick
How did you test your code?

SE-2030 2
Dr. Mark L. Hornick
How can you test your app?
 Run the app with inputs that should produce a known
output, and verify the actual output
One problem with this approach may be that you can’t make
your app accept “bad” inputs; thus you may not be able to force
all possible if-then-else blocks of the app’s classes’ methods to
execute

 Write a separate “test” program that is designed to


exercise the classes and methods of the “production”
app
A problem with this might be gathering the results of the
exercises and determining whether each one passed or failed.

SE-2030 3
Dr. Mark L. Hornick
What is Unit Testing?
 Creating special-purpose test code that exercises
specific classes of your application is called Unit
Testing
 Unit Testing is also known as “Class Testing”
 Such test code usually exercises one method of a
class at a time whenever possible.
 The tests usually include exercising the methods
in “boundary conditions” by force-feeding the
methods “bad” arguments, such as nulls.

SE-2030 4
Dr. Mark L. Hornick
Naïve Demo

SE-2030 5
Dr. Mark L. Hornick
What is JUnit?
 JUnit is an open source Java testing framework used to write
and run repeatable tests.

 It is built into Eclipse (and ItelliJ etc)

 JUnit is designed to automatically call “test” methods that in


turn test the “real” code.
 It can compare actual results the “test” received from a real method vs.
the results it expected, and report deviations.
 It does not guarantee that the methods it calls actually perform
meaningful tests
 You must write meaningful tests
 You must write “enough” tests to cover all possible situations

SE-2030 6
Dr. Mark L. Hornick
What are some limitations of
JUnit testing?
 Not well-suited for testing user interfaces (other
approaches are needed)
 Does not ensure that all code is actually tested
(other tools are needed to measure code
coverage)
 Is not well-suited for testing an entire application
 Complexities related to testing private methods

These topics are covered in more detail in SE2832


SE-2030 7
Dr. Mark L. Hornick
Demonstration

SE-2030 8
Dr. Mark L. Hornick

You might also like