Skip to content

Commit 17ce07a

Browse files
committed
Move common setup methods to common setup test class.
1 parent b70a538 commit 17ce07a

File tree

5 files changed

+72
-120
lines changed

5 files changed

+72
-120
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="test"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="commonSetupTests.m" type="File"/>

tests/commonSetupTests.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
classdef commonSetupTests < matlab.unittest.TestCase
2+
3+
properties (Constant)
4+
firmwarePath = fullfile(getenv('firmwareSharePath'),matlabRelease.Release)
5+
end
6+
7+
properties
8+
bd bossdevice
9+
sgPath
10+
isSGinstalled
11+
end
12+
13+
methods (TestClassSetup)
14+
function setupBossdevice(testCase)
15+
[testCase.isSGinstalled, testCase.sgPath] = bossapi.isSpeedgoatBlocksetInstalled;
16+
if testCase.isSGinstalled
17+
% If local installation of Speedgoat blockset is present, update toolbox dependencies and work with them
18+
bossapi.removeSpeedgoatBlocksetFromPath(testCase.sgPath);
19+
end
20+
21+
testCase.bd = bossdevice;
22+
testCase.bd.targetObject.update;
23+
24+
fprintf('Wait 30s for target to reboot after update and set IP address in secondary interface.\n');
25+
pause(30);
26+
% Set Ethernet IP in secondary interface
27+
bossapi.setEthernetInterface(testCase.bd.targetObject,'wm1','192.168.200.255/24');
28+
end
29+
30+
function addFirmwarePath(testCase)
31+
import matlab.unittest.fixtures.PathFixture
32+
if isfolder(testCase.firmwarePath)
33+
testCase.applyFixture(PathFixture(testCase.firmwarePath));
34+
end
35+
end
36+
end
37+
38+
methods (TestClassTeardown)
39+
function resetSgPath(testCase)
40+
if testCase.isSGinstalled
41+
% If local installation of Speedgoat blockset is present, restore default paths
42+
bossapi.addSpeedgoatBlocksetToPath(testCase.sgPath);
43+
end
44+
end
45+
46+
function rebootTarget(testCase)
47+
disp('Rebooting bossdevice to teardown test class.');
48+
testCase.bd.targetObject.reboot;
49+
pause(30);
50+
end
51+
end
52+
53+
methods (TestMethodTeardown)
54+
function clearBossdeviceObj(testCase)
55+
if ~isempty(testCase.bd) && testCase.bd.isConnected
56+
testCase.bd.stop;
57+
testCase.bd.targetObject.disconnect;
58+
end
59+
end
60+
end
61+
62+
end

tests/exampleTests.m

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,10 @@
1-
classdef exampleTests < matlab.unittest.TestCase
1+
classdef exampleTests < commonSetupTests
22
%EXAMPLETESTS Execute all shipping examples
33

4-
properties (Constant)
5-
firmwarePath = fullfile(getenv('firmwareSharePath'),matlabRelease.Release)
6-
end
7-
84
properties (TestParameter)
95
exName = {'demo_jittered_open_loop_stimulation'}
106
end
117

12-
properties
13-
bd bossdevice
14-
sgPath
15-
isSGinstalled
16-
end
17-
18-
methods (TestClassSetup)
19-
function setupBossdevice(testCase)
20-
[testCase.isSGinstalled, testCase.sgPath] = bossapi.isSpeedgoatBlocksetInstalled;
21-
if testCase.isSGinstalled
22-
% If local installation of Speedgoat blockset is present, update toolbox dependencies and work with them
23-
bossapi.removeSpeedgoatBlocksetFromPath(testCase.sgPath);
24-
end
25-
26-
testCase.bd = bossdevice;
27-
testCase.bd.targetObject.update;
28-
29-
fprintf('Wait 30s for target to reboot after update and set IP address in secondary interface.\n');
30-
pause(30);
31-
% Set Ethernet IP in secondary interface
32-
bossapi.setEthernetInterface(testCase.bd.targetObject,'wm1','192.168.200.255/24');
33-
end
34-
35-
function addFirmwarePath(testCase)
36-
import matlab.unittest.fixtures.PathFixture
37-
if isfolder(testCase.firmwarePath)
38-
testCase.applyFixture(PathFixture(testCase.firmwarePath));
39-
end
40-
end
41-
end
42-
43-
methods (TestClassTeardown)
44-
function resetSgPath(testCase)
45-
if testCase.isSGinstalled
46-
% If local installation of Speedgoat blockset is present, restore default paths
47-
bossapi.addSpeedgoatBlocksetToPath(testCase.sgPath);
48-
end
49-
end
50-
51-
function rebootTarget(testCase)
52-
disp('Rebooting bossdevice to teardown test class.');
53-
testCase.bd.targetObject.reboot;
54-
pause(30);
55-
end
56-
end
57-
58-
methods (TestMethodTeardown)
59-
function stopBossdevice(testCase)
60-
if testCase.bd.isConnected && testCase.bd.isRunning
61-
testCase.bd.stop;
62-
pause(5);
63-
end
64-
end
65-
end
66-
678
methods (Test, TestTags = {'bdConnected'})
689
function runExampleScript(~, exName)
6910
run(exName);

tests/smokeTests.m

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,4 @@
1-
classdef smokeTests < matlab.unittest.TestCase
2-
3-
properties (Constant)
4-
firmwarePath = fullfile(getenv('firmwareSharePath'),matlabRelease.Release)
5-
end
6-
7-
properties
8-
bd bossdevice
9-
sgPath
10-
isSGinstalled
11-
end
12-
13-
methods (TestClassSetup)
14-
function setupBossdevice(testCase)
15-
[testCase.isSGinstalled, testCase.sgPath] = bossapi.isSpeedgoatBlocksetInstalled;
16-
if testCase.isSGinstalled
17-
% If local installation of Speedgoat blockset is present, update toolbox dependencies and work with them
18-
bossapi.removeSpeedgoatBlocksetFromPath(testCase.sgPath);
19-
end
20-
21-
testCase.bd = bossdevice;
22-
testCase.bd.targetObject.update;
23-
24-
fprintf('Wait 30s for target to reboot after update and set IP address in secondary interface.\n');
25-
pause(30);
26-
% Set Ethernet IP in secondary interface
27-
bossapi.setEthernetInterface(testCase.bd.targetObject,'wm1','192.168.200.255/24');
28-
end
29-
30-
function addFirmwarePath(testCase)
31-
import matlab.unittest.fixtures.PathFixture
32-
if isfolder(testCase.firmwarePath)
33-
testCase.applyFixture(PathFixture(testCase.firmwarePath));
34-
end
35-
end
36-
end
37-
38-
methods (TestClassTeardown)
39-
function resetSgPath(testCase)
40-
if testCase.isSGinstalled
41-
% If local installation of Speedgoat blockset is present, restore default paths
42-
bossapi.addSpeedgoatBlocksetToPath(testCase.sgPath);
43-
end
44-
end
45-
46-
function rebootTarget(testCase)
47-
disp('Rebooting bossdevice to teardown test class.');
48-
testCase.bd.targetObject.reboot;
49-
pause(30);
50-
end
51-
end
52-
53-
methods (TestMethodTeardown)
54-
function clearBossdeviceObj(testCase)
55-
if ~isempty(testCase.bd) && testCase.bd.isConnected
56-
testCase.bd.stop;
57-
testCase.bd.targetObject.disconnect;
58-
end
59-
end
60-
end
1+
classdef smokeTests < commonSetupTests
612

623
methods (Test, TestTags = {'noHW'})
634
% Test methods that do not require bossdevice or any target connected

0 commit comments

Comments
 (0)