Skip to content
MathWorks

Self-Paced Online Courses

  • MATLAB Help Center
  • Community
  • Learning
  • Get MATLAB MATLAB
  • Sign In
    • My Account
    • My Community Profile
    • Link License

    • Sign Out
  • Contact MathWorks Support
  • Visit mathworks.com
    • Self-Paced Content
    • MathWorks
    • MATLAB MATLAB
    • Help Center Help Center
    • MathWorks MathWorks
    • MATLAB Answers MATLAB Answers
    • File Exchange File Exchange
    • Videos Videos
    • Online Training Online Training
    • Blogs Blogs
    • Cody Cody
    • MATLAB Drive MATLAB Drive
    • ThingSpeak ThingSpeak
    • Bug Reports Bug Reports
    • Community Community
  • Online Courses
MathWorks MathWorks

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.

United States

  • United States (English)
  • United States (Deutsch)
  • United States (Français)
  • United States(简体中文)
  • United States (English)

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文
    • English
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

image for course Unit Testing

Unit Testing

Learn to write effective unit tests to improve code quality, prevent bugs, and verify desired behavior. Understand test concepts, write test scripts and functions, and manage pre- and post-test tasks.

Course modules

Introduction

Get an overview of the content covered.

Lessons:
  • Course Overview
  • Learning Outcomes and Prerequisites
  • Course Example
  • What is Unit Testing?

What is a Test?

Write tests with comparisons, functions that test equality, and assert statements.

Lessons:
  • Elements of a Test
  • is* Functions
  • Compare with == Versus isequal
  • Test Response
  • Assert Statements

Test as You Go with a Test Script

Combine tests into a test script, and run tests on your code base.

Lessons:
  • Why Use a Test Script?
  • The Format of a Test Script
  • Write a Test Script
  • Test Script Results
  • Run a Test Script
  • Fix Broken Tests

Avoid Bugs in Comparisons

Use tests that make numeric comparisons within a given tolerance.

Lessons:
  • Bugs in Comparisons
  • Numerical Precision
  • Check for Equality (Within a Given Tolerance)
  • Add a Tolerance to Satellite Application Tests

Write Test Functions

Write test functions to test the output and behavior of programs.

Lessons:
  • Why Use Test Functions?
  • The Format of a Test Function
  • Convert Satellite Parameters Tests to Test Functions

Verify Behavior

Use functions that verify application behavior.

Lessons:
  • Verify Application Behavior
  • Verification Functions
  • Satellite Parameters Tests Using verifyTrue
  • Other verify* Functions

Test for Desired Warnings and Errors

Verify programs produce the correct warnings and errors.

Lessons:
  • Commands as Inputs to Test
  • Test for an Expected Error Message - Satellite Application
  • Test for an Expected Error Message - Square Root Function

Add Pre- and Post- Test Tasks

Define set-up tasks for testing, and undo them when finished.

Lessons:
  • What Are Pre- and Post-Test Tasks?
  • The Format of Pre- and Post- Test Tasks
  • Pre- and Post- Test Tasks for Satellite Parameters Tests

Conclusion

Review course content, learn next steps, and provide feedback on the course.

Lessons:
  • Summary
  • Additional Resources
  • Survey

Format:Self-paced

Language:English

Language

  • Hands-on exercises with automated feedback
  • Access to MATLAB through your web browser
  • Shareable progress report and course certificate

The How and Why of Writing Functions

Increase the flexibility of your code by writing custom functions.

  • Home
  • My Courses
  • Online Training Suite
Loading
  • Trust Center
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status
  • Contact Us

© 1994-2025 The MathWorks, Inc.