-
Notifications
You must be signed in to change notification settings - Fork 0
TestTemplate Documentation
The TestTemplate class is the main class used in the Template Design Pattern.
-
The TestTemplate class is an abstract class that contains attributes inherited b the 5 subclasses, i.e. FlightTest, PassengerTest, LuggageSlipTest, LuggageManifestTest and LuggageManagementSystemTest. There is no instance required to be created in order to utilize this class as it only acts as a template. The template contains abstract methods which all subclasses must implement to adhere to the design pattern.
-
This class extends the Exception class.
-
The main methods implemented are as follows:
protected void runFieldTest(Class<?> testClass, String fName, String mod,String typeJ,String typeN)protected void checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum)public static int getPassedTestsMark()public static int getCleanCodeMarks()public abstract void init()public abstract void testToString()
Methods
The below methods are used as helper methods in testing the naming conventions of class attributes and methods.
-
protected void runFieldTest(Class<?> testClass, String fName, String mod,String typeJ,String typeN): Helper methos used to validate the naming conventions of the specified attributes.
-
protected Field getField(String fieldName): Helper method used to retrieve the specified attribute using reflection.
-
protected void checkDeclaredOnly(): Helper method used to determine whether a variable has been only declared or initialized.
-
protected void checkExpectedField(String fieldName, String expectedField): Helper method used to validate the accuracy of the attribute conventions supplied by the student to the expected conventions.
-
protected void checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum): Helper method used to validate the naming conventions of the submitted class methods.
-
public static int getPassedTestsMark(): Getter method for the passedTestsMark attribute.
-
public static int getCleanCodeMarks(): Getter method for the cleanCodeMarks attribute.
-
public abstract void init(): Abstract method implemented by all subclass, used to reinitialize requisite attributes
-
public abstract void testToString(): Abstract method implemented by subclasses for object representation in String form.
Fields
-
protected String response: Used to store feedback responses for each test. This attribute is reinitialized to '' before each test.
Methods utilized in:
checkDeclaredOnly()checkExpectedField(String fieldName, String expectedField)checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum)runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)- All class tests
getField(String fieldName)
-
protected int mark: Used to store the appropriate mark for each test result. This attribute is reinitialized to 0 before each test.
Methods utilized in:
getPassedTestsMark()getCleanCodeMarks()checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum)runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)- All class tests
-
protected boolean passed: Used to indicate whether the test has passed or failed.
Methods utilized in:
checkDeclaredOnly()checkExpectedField(String fieldName, String expectedField)checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum)- All class tests
getField(String fieldName)
-
protected boolean declaredOnly: Used to indicate whether the variable was only declared and not intialized.
Methods utilized in:
checkDeclaredOnly()
-
protected String typeJavaName: Used to store the generic Java syntax for the attribute type.
Methods utilized in:
runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected String typeName: Used to store the simplified attribute type name.
Methods utilized in:
runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected String modifier: Used to indicate the expected access modifier for the tested attribute.
Methods utilized in:
checkExpectedField(String fieldName, String expectedField)runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected String className: Initialized in each test class to indicate the current class being test.
-
protected Field field: Used the store the specified field object from the class being tested
Methods utilized in:
runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected Object value: Used to store the value of the retrieved field.
Methods utilized in:
checkDeclaredOnly()
-
protected Passenger passenger: An initialized attribute of type Passenger used by test classes for testing.
-
protected String fieldName: Initialized by each attribute test to indicate the current attribute being tested.
Methods utilized in:
runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)getField(String fieldName)checkExpectedField(String fieldName, String expectedField)
-
protected String expectedField: The String representation of the expected field declaration.
Methods utilized in:
checkExpectedField(String fieldName, String expectedField)runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected Class<?> testClass: Initialized by each test class to indicate to the TestTemplate methods the class currently being tested.
Methods utilized in:
getField(String fieldName)checkExpectedField(String fieldName, String expectedField)checkMethod(String methodName, String genericReturnType, String normalReturnType, String normalParaTypes, Class<?>... classSum)runFieldTest(Class<?> testClass, String fName, String mod, String typeJ, String typeN)
-
protected static int cleanCodeMark: A dedicated attribute that is initialized to 5 and decremented with each failed naming convention test, thereby determining the mark to be awarded for "Clean code"
Methods utilized in:
getPassedTestsMark()getCleanCodeMarks()
-
protected static int passedTestsMark: A dedicated attribute that is initialized to 14 and decremented with each failed test, thereby determining the mark to be awarded for "Passed JUnit Tests"
Methods utilized in:
getPassedTestsMark()getCleanCodeMarks()