Class-based tests with CurrentFolderFixture excluded from testsuite unless run manually
Mostra commenti meno recenti
I'm getting started with using class-based unit tests on my code, and I want to create a testsuite script to run all of my test methods. Right now I have each test in its own subfolder of a folder (UnitTest/Module/Submodule1,UnitTest/Module/Submodule2, etc), and I'm calling:
suite = testsuite('UnitTest/Module', 'IncludingSubfolders', true);
The error I'm having is that the tests are being excluded with the following warning messages:
Warning: "C:\MyProject\UnitTest\Module\Submodule1\Submodule1UnitTest.m" was excluded.
Caused by:
Error: File: Submodule1UnitTest.m Line: 6 Column: 38
Folder "UnitTest/Module/Submodule1/" cannot be found.
> In matlab.unittest.internal.InvalidTestFactory/createSuiteImplicitly (line 37)
In matlab.unittest.TestSuite.fromFolder (line 583)
In matlab.unittest.TestSuite>@(fld)TestSuite.fromFolder(fld,selector,'IncludingSubfolders',includeSubfolders) (line 599)
In matlab.unittest.TestSuite.fromFolder (line 599)
In testsuite>createSuite (line 221)
In testsuite (line 128)
In ModuleRunAllTests (line 1)
The line it's pointing to as the error is where I define the CurrentFolderFixture test fixture.
%% Submodule1 Unit Test
% Author: Pi
%
% Created: 10/27/2022
classdef (SharedTestFixtures={matlab.unittest.fixtures.CurrentFolderFixture( ...
'UnitTest/Module/Submodule1/')}) ...
Submodule1UnitTest < BaselineTestCase
BaselineTestCase is inheriting from matlab.unittest.TestCase.
What's weird is that the test is excluded unless I manually run the test in the matlab session first. Once I've manually run the test outside of the testsuite, then the testsuite will include the test and run it as expected. The script for generating the testsuite currently lives in 'MyProject/UnitTest/', and I am running the script with my working directory as 'MyProject/', but I have also had the same problem when running with directly from 'MyProject/UnitTest/'.
Any ideas what could be causing the tests to be excluded, or why running the tests manually would allow testsuite to find them?
Risposta accettata
Più risposte (1)
Marek Plotka
il 31 Mag 2023
0 voti
In matlab version since R2022b you can use 'InvalidFileFoundAction' parameter set to 'error':
Categorie
Scopri di più su Run MATLAB Tests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!