Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exception testing Aistis Karkauskas, IFM-2/2. Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing.

Similar presentations


Presentation on theme: "Exception testing Aistis Karkauskas, IFM-2/2. Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing."— Presentation transcript:

1 Exception testing Aistis Karkauskas, IFM-2/2

2 Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution  Exception handling is the process of responding to the occurrence, during computation, of exceptions 2

3 Errors - Throw and Try to Catch  The try statement lets you to test a block of code for errors  The catch statement lets you handle the error  The throw statement lets you create custom errors 3

4 When to use exception handling?  The method you choose depends on how often you expect the event to occur  If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case 4

5 Example 1  The following example uses an if statement to check whether a connection is closed if (conn.State != ConnectionState.Closed) { conn.Close(); } 5

6 Example 2  In the following example, an exception is thrown if the connection is not closed try { conn.Close(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } 6

7 Exceptions vs. Traditional Error- Handling Methods  Failures do not go unnoticed  Invalid values do not continue to propagate through the system  You do not have to check return codes  Exception-handling code can be easily added to increase program reliability  Resources are only used when an exception occurs 7

8 Exception testing  Exception testing is defined as a complete and honest effort to break the system. With Exception testing, the team tries to dream up every conceivable way that users will run bad data through the system and make sure that: 1: The system does not crash 2: The system is able to stop the bad data 3: The system reports the root cause of the problem in an understandable way and suggests possible ways of fixing it 8

9 Exception handler testing  Exception handler testing is used to check if exceptions are being handled  Unit tests can be created which can test if exception is thrown  In this case we can state that exception handler testing is a white box method 9

10 Example 1 10

11 Example 2 11

12 Flaw  In some cases it is hard to imitate an exception which should be handled 12

13 Unit testing frameworks  NUnit (an open source unit testing framework for Microsoft.NET)  JUnit (is a unit testing framework for the Java programming language)  PyUnit (is a Python language version of JUnit) 13

14 Questions 14

15 1. What is the definition of exception? 2. Which statement is used to initiate a block of code for error checking? 3. Which statement is used to initiate exception handling? 4. When to use exception handling? 5. Name at least two things why exception handling is better than traditional error- handling methods? 15


Download ppt "Exception testing Aistis Karkauskas, IFM-2/2. Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing."

Similar presentations


Ads by Google