Package: ParamNoResultFileTest

ParamNoResultFileTest

nameinstructionbranchcomplexitylinemethod
ParamNoResultFileTest(String, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
checkAssumptions()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
testCase()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * Overture Testing Framework
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.core.testing;
23:
24: import java.io.IOException;
25: import java.util.List;
26:
27: import org.junit.Test;
28: import org.overture.ast.node.INode;
29: import org.overture.parser.lex.LexException;
30: import org.overture.parser.syntax.ParserException;
31:
32: /**
33: * No result file test in the new Overture test framework. This class runs testing on (correct) VDM sources. Test result
34: * storage (if any) is left entirely up to the developer.
35: * <br>
36: * These testing are meant to be run as parameterized JUnit test and so any subclass must be annotated with
37: * <code>@RunWith(Parameterized.class)</code>. <br>
38: * <br>
39: * This class also has a type parameter <code>R</code> that represents the output of the functionality under test. You
40: * should create a specific <code>R</code> type for your functionality and write some kind of transformation between
41: * your native output type and <code>R</code>.
42: *
43: * @author ldc
44: * @param <R>
45: */
46: public abstract class ParamNoResultFileTest<R>
47: {
48:
49:         protected String modelPath;
50:         protected String testName;
51:
52:         /**
53:          * Constructor for the test. In order to use JUnit parameterized testing, the inputs for this class must be supplied
54:          * by a public static method. Subclasses must implement this method themselves and annotate with
55:          * <code>@Parameters(name = "{index} : {0}")</code>.<br>
56:          * <br>
57:          * The {@link PathsProvider#computePathsNoResultFiles(String...)} method produces the correct input for this constructor and
58:          * should be called with the root folder of your testing inputs as its argument.
59:          *
60:          * @param nameParameter
61:          * the name of the test. Normally derived from the test input file
62:          * @param inputParameter
63:          * file path for the VDM source to test
64:          */
65:         public ParamNoResultFileTest(String nameParameter, String inputParameter)
66:         {
67:                 this.testName = nameParameter;
68:                 this.modelPath = inputParameter;
69:         }
70:
71:         /**
72:          * Execute this test. Constructs the AST for the model and processes it via {@link #processModel(List)}. Then the
73:          * output of the analysis is evaluated via {@link #processResult(Object)}.
74:          * <br>
75:          * This test is not designed to run on VDM sources with syntax or type errors. The test will fail if the source
76:          * fails to parse or type check. While this behavior can be overridden, we suggest looking at
77:          * {@link ParamFineGrainTest} if you need to cope with these errors.
78:          *
79:          * @throws IOException
80:          * @throws LexException
81:          * @throws ParserException
82:          */
83:         @Test
84:         public void testCase() throws ParserException, LexException, IOException
85:         {
86: checkAssumptions();
87:                 List<INode> ast = ParseTcFacade.typedAst(modelPath, testName);
88:                 R actual = processModel(ast);
89:                 processResult(actual);
90:         }
91:
92:         /**
93:          * Analyse a test result. This method is called during test execution. It must, of course, be
94:          * overridden to perform result analysis as desired for this test.Don't forget to assert something!
95:          *
96:          * @param actual
97:          * the result of processing the model per {@link #processModel(List)}
98:          */
99:         protected abstract void processResult(R actual);
100:         
101:         /**
102:          * Analyse a model. This method is called during test execution to produce the actual result. It must, of course, be
103:          * overridden to perform whatever analysis the functionality under test performs.<br>
104:          * <br>
105:          * The output of this method must be of type <code>R</code>, the result type this test runs on. You will will likely
106:          * need to have a conversion method between the output of your analysis and <code>R</code>.
107:          *
108:          * @param ast
109:          * the model to process
110:          * @return the output of the analysis
111:          */
112:         public abstract R processModel(List<INode> ast);
113:
114:         /**
115:          * This is the first method to be invoked in the test case. It provides a convenient place to place
116:          * {@link org.junit.Assume} assumptions.
117:          */
118:         public void checkAssumptions(){};
119: }