Questa pagina si riferisce alla release precedente. La corrispondente pagina in inglese è stata rimossa nella release attuale.
Test delle unità basati su classi
Scrivere test basati su classi; parametrizzare i test; applicare gli impianti; selezionare ed eseguire i test
Scrivere test in stile xUnit per verificare che l'output del codice MATLAB® sia quello previsto. I test delle unità basati sulle classi consentono di accedere a tutte le funzionalità del framework di test delle unità. Ad esempio, è possibile scrivere test parametrizzati, etichettare i test o utilizzare gli impianti di test condivisi.
Per iniziare, vedere Author Class-Based Unit Tests in MATLAB e Write Simple Test Case Using Classes.
App
Test Browser | Run MATLAB tests and view results (Da R2023a) |
Funzioni
runtests | Run set of tests |
testsuite | Create suite of tests |
testrunner | Create test runner (Da R2021a) |
run (TestSuite) | Run test suite using default test runner |
run (TestRunner) | Run test suite |
run (TestCase) | Run tests corresponding to test case |
runInParallel | Run all tests in test suite in parallel |
Classi
matlab.unittest.TestCase | Superclass of all test classes |
matlab.unittest.TestSuite | Fundamental interface for grouping tests to run |
matlab.unittest.Test | Specification of a single test |
matlab.unittest.TestRunner | Class for running tests in unit testing framework |
matlab.unittest.TestResult | Result of running test suite |
Namespaces
matlab.unittest | Summary of classes and namespaces in MATLAB unit testing framework |
matlab.unittest.qualifications | Summary of classes in MATLAB qualifications interface |
matlab.unittest.constraints | Summary of classes in MATLAB constraints interface |
matlab.unittest.fixtures | Summary of classes in MATLAB fixtures interface |
matlab.unittest.parameters | Summary of classes associated with MATLAB unit testing parameters |
matlab.unittest.plugins | Summary of classes in MATLAB plugins interface |
matlab.unittest.selectors | Summary of classes in MATLAB selectors interface |
Simulink.sdi.constraints.MatchesSignal | Constraint that compares time series data with tolerances using the Simulation Data Inspector |
Argomenti
Scrittura di test
- Author Class-Based Unit Tests in MATLAB
To test a MATLAB program, write a unit test using qualifications that are methods for testing values and responding to failures. - Write Simple Test Case Using Classes
Write class-based unit tests to determine the correctness of your program. - Write Setup and Teardown Code Using Classes
Specify setup and teardown code that runs before and after eachTest
method or allTest
methods in a test class. - Write Tests Using Shared Fixtures
Share fixtures across test classes when creating tests. - Tag Unit Tests
Use test tags to group tests into categories and then run tests with specified tags. Typical test tags identify a particular feature or describe the type of test. - Insert Test Code Using Editor
Write a parameterized test interactively by using the options in the MATLAB Editor. - Table of Verifications, Assertions, and Other Qualifications
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
Scrittura di test parametrizzati
- Use Parameters in Class-Based Tests
Use parameters to provide data for your tests to use iteratively. - Create Basic Parameterized Test
Test a function by creating a test that is parameterized in theTest
methods
block. - Create Advanced Parameterized Test
Create a test that is parameterized in theTestClassSetup
,TestMethodSetup
, andTest
methods
blocks. - Define Parameters at Suite Creation Time
Use aTestParameterDefinition
method to define parameters at test suite creation time. - Use External Parameters in Parameterized Test
Use data-driven testing to inject variable inputs into your parameterized test.
Esecuzione dei test e analisi dei risultati
- Create Simple Test Suites
Combine tests into test suites, whether they are organized in namespaces and classes or files and folders, or both. - 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. (Da R2023a) - Run Tests in Editor
Run your tests while working in the Editor or Live Editor. - Analyze Test Case Results
Analyze the information that a test runner returns. - Analyze Failed Test Results
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. Monitor the filtered tests for test code that the testing framework does not execute. - Programmatically Access Test Diagnostics
Programmatically access the diagnostics that the testing framework records on test results. - Add Plugin to Test Runner
Add a plugin to the test runner. - Types of Code Coverage for MATLAB Source Code
Use different types of code coverage to analyze your MATLAB source code. - Collect Statement and Function Coverage Metrics for MATLAB Source Code
Collect and analyze information about statement and function coverage for your MATLAB source code. - Compile MATLAB Unit Tests
Create a standalone application to run your tests on target machines that do not have MATLAB installed.