Pruebas unitarias basadas en funciones
Escriba pruebas usando calificaciones; personalice el ejecutor de pruebas; seleccione y ejecute pruebas
Escriba pruebas basadas en funciones para comprobar que las salidas de los scripts, funciones o clases de MATLAB® son las que espera. Es posible usar una biblioteca completa de funciones de calificaciones para producir cuatro tipos diferentes de errores de prueba. Por ejemplo, es posible producir errores de verificación o errores de aserción fatales. Las pruebas basadas en funciones se adhieren a la filosofía de pruebas xUnit.
Para comenzar, consulte Write Function-Based Unit Tests y Write Simple Test Case Using Functions.
Para la creación de pruebas más avanzadas, incluido el uso de parametrización de prueba y accesorios de prueba, considere escribir Pruebas unitarias basadas en clases.
Apps
Test Browser | Run MATLAB tests and view results (desde R2023a) |
Funciones
functiontests | Create array of tests from handles to local functions |
runtests | Run set of tests |
testsuite | Create suite of tests |
testrunner | Create test runner (desde R2021a) |
run (TestSuite) | Run test suite using default test runner |
Clases
Test | Specification of a single test |
FunctionTestCase | TestCase used for function-based tests |
TestResult | Result of running test suite |
Temas
Escribir pruebas
- Write Function-Based Unit Tests
Your test function is a single MATLAB file that contains a main function and your individual local test functions. Optionally, you can include file fixture and fresh fixture functions. - Write Simple Test Case Using Functions
Write function-based unit tests to determine the correctness of your program. - Write Test Using Setup and Teardown Functions
Write a function-based test with setup and teardown functions that run once in your test file and before and after each test function in the file. - Table of Verifications, Assertions, and Other Qualifications
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
Ejecutar pruebas y analizar resultados
- Run Tests for Various Workflows
Explore different ways to run tests. - Run Tests Using Test Browser
Run your tests interactively by using the test browser. (desde R2023a) - Run Tests in Editor
Run your tests while working in the Editor or Live Editor. - Analyze Test Case Results
This example shows how to analyze the information returned by a test runner. - Analyze Failed Test Results
This example shows how to identify and handle failed tests. - Rerun Failed Tests
Rerun failed tests quickly and conveniently. - Dynamically Filtered Tests
Assumption failures produce filtered tests that are marked asIncomplete
instead of producing test failures. To avoid test code that is not executed, monitor the filtered tests. - Extend Function-Based Tests
Access additional functionality using function-based tests, including application of fixtures, test selection, programmatic access of test diagnostics, and test runner customization.