MT2 Flashcards
What are documentation comments?
- comment statements that use triple forward slashes (///) and XML formatted comment body
- must precede a user-defined type / member
What is an XML
Extensible Markup Language
- readable to both human and machines
- uses tags ex. < summary> and </ summary>
what is the tag: <summary>
- brief info abt type / type member (appears as first comment)
what is the tag: <param></param>
- describe method parameters
ex. <param></param> First addition operand. </param> - DON’T include type in parameter
what is the tag: <return></return>
describe return value of method
what is the tag: <exception></exception>
inform that the method can throw specific exceptions.
<exception>
</exception>
What is Unit Testing?
process of testing program components (methods / object classes)
- automatically test all units
How does unit testing distinguish class from method
By using attributes
class –> [TestClass()]
method –> [TestMethods()]
What is the pattern of a unit test
- Arrange
- initalize and select test case - Act
- call method to be tested - compare result of call with expected result
How to write a unit test that expects an exception?
use attribute –>
[ExpectedException(typeof(“insert specific exception”)]
What is an exception?
Runtime error –>
1. program violates system / application contstraint
2. There is a condition that is not normally expected
4 types of exception Handling
- corrective actions
- log information about error
- clean up before terminating
(ex. closing files) - Display error message before terminating
3 components of Try/ Catch Statements
- Try Block:
Contains statements being guarded for exceptions (ex. statements that might throw an exception) - Catch Clause:
Contains exception handlers - Finally Block
Contains code to be executed (whether or not exception is thrown)
2 common forms of Catch Statement
- catch( ExceptionType)
- matches any exception of the named type - catch (ExceptionType, ExceptionVariable)
- identifier (second parameter) acts as local variable and references exception object (used to access info about object)
Two Main Types of Exceptions
- SystemException
- base class for exceptions in C# base library
2.ApplicationException
- programmers create own exception classes
What is a specification?
description of what a type or a type member does
- may apply to entire programs, or functions/methods
also describes preconditions and postconditions
constrains (input) domain and (output) range of a method
Benefits of Specifications
Acts as a contract between implementer and consumer/client
Implementer:
- freedom to change implementation
- easier to determine errors
Consumer/ client:
- use methods without reading code
- describe how to ensure you get expected result
What is a precondition
(“requires”)
- a condition that must be true in order for implementation to work
- if not true, behaviour is undefined (exceptions, crashses, infinite loops)
What is a postcondition
(“effects” or “returns”)
- what the implementer of method promises to do
- often states what it returns
What is a frame condition
- identifies which objects may be modified
(therefore implicitly tells which object is not modified) - if omitted: nothing is modified