Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.

Slides:



Advertisements
Similar presentations
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
GoogleTest Primer. Outline Basic Concepts Assertions Basic Assertions Binary Comparison String Comparison Floating-Point Comparison Simple Tests Test.
A problem with functions: arguments must always have values that can be worked out Whenever we call a function we give it arguments. Lisp then works out.
Introduction to C Programming
GoogleMock for Dummies
Debugging Introduction to Computing Science and Programming I.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
Testing Michael Ernst CSE 140 University of Washington.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
October, 2006 © Copyright 2006, Larry A. Beaty. Copying and distribution of this document is permitted in any medium, provided this notice is preserved.
Selection Structures Tonga Institute of Higher Education.
Google C++ Testing Framework Death Tests. In many applications, there are assertions that can cause application failure if a condition is not met. ◦ Square.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Oracle Data Integrator Procedures, Advanced Workflows.
Introduction to Exception Handling and Defensive Programming.
1.  Writing snippets of code that try to use methods (functions) from your program.  Each snippet should test one (and only one) function......by calling.
Chapter 24 Exception CSC1310 Fall Exceptions Exceptions Exceptions are events that can modify the flow or control through a program. They are automatically.
TK 1914 : C++ Programming Control Structures I (Selection)
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
12/14/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
CPS120 Introduction to Computer Science Iteration (Looping)
Operator Overloading Week 5.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Google C++ Testing Framework Test Fixtures: Using the Same Data Configuration for Multiple Tests.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
Unit Testing with FlexUnit
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Lec 24 Googletest - 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Lecture 24 Google C++ Framework 11/20/
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 14: Sequential Access Files
Introduction to Decision Structures and Boolean Variables
Class Invariants Class invariants are logical conditions to ensure the correct working of a class. Class invariants must hold true when an object is created,
similar concepts, different syntax
Chapter 6 CS 3370 – C++ Functions.
Dept of Computer Science University of Maryland College Park
Introduction to JUnit CS 4501 / 6501 Software Testing
Compilation and Debugging
Compilation and Debugging
JavaScript: Control Statements.
5 Categorical Syllogisms
Control Structures – Selection
Conditions and Ifs BIS1523 – Lecture 8.
Organize your code with MVC
Testing and Test-Driven Development CSC 4700 Software Engineering
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to Computer Programming
CS 1111 Introduction to Programming Fall 2018
Logical Operations In Matlab.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Error Handling.
Unit Testing.
Presentation transcript:

Google C++ Testing Framework Part 2: Assertion

Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect the structure of the tested code. ◦ When multiple tests in a test case need to share common objects and subroutines, you can put them into a test fixture class. A test program can contain multiple test cases.

Assertions Assertion are statements that check whether a condition is true An assertion's result can be success, nonfatal failure, or fatal failure. If a fatal failure occurs, it aborts the current function; otherwise the program continues normally. Tests use assertions to verify the tested code's behavior. If a test crashes or has a failed assertion, then it fails; otherwise it succeeds.

Types of assertions ASSERT_* : generate fatal failures when they fail, and abort the current function. ◦ if it doesn't make sense to continue when the assertion in question fails. EXPECT_* : generate nonfatal failures, which don't abort the current function. ◦ allow more than one failures to be reported in a test.

Demo

Add Custom Message

Basic Assertions Remember, when they fail, ASSERT_* yields a fatal failure and returns from the current function, EXPECT_* yields a nonfatal failure, allowing the function to continue running. In either case, an assertion failure means its containing test fails.

Binary Comparison

String Comparison

Simple Tests Steps to create tests ◦ Use the TEST() macro to define and name a test function, These are ordinary C++ functions that don't return a value. ◦ In this function, along with any valid C++ statements you want to include, use the various Google Test assertions to check values. ◦ The test's result is determined by the assertions; if any assertion in the test fails (either fatally or non-fatally), or if the test crashes, the entire test fails. Otherwise, it succeeds. Multiple tests inside body, only one name

Demo -Factorial CodeConcepts mapping Google Test groups the test results by test cases, so logically- related tests should be in the same test case; ◦ the first argument to their TEST() should be the same. Test case ◦ FactorialTest. Two tests, ◦ HandlesZeroInput and ◦ HandlesPositiveInput,

Any problem? Mixed Implementation and testing How to separate? e/browse/#svn/trunk/samples e/browse/#svn/trunk/samples Example 1