Lec 24 Googletest - 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Lecture 24 Google C++ Framework 11/20/2013 1.

Slides:



Advertisements
Similar presentations
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
GoogleTest Primer. Outline Basic Concepts Assertions Basic Assertions Binary Comparison String Comparison Floating-Point Comparison Simple Tests Test.
Programming Types of Testing.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
DT211/3 Internet Application Development
Microsoft ASP.NET AJAX - AJAX as it has to be Presented by : Rana Vijayasimha Nalla CSCE Grad Student.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
Introduction to a Programming Environment
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
C++ fundamentals.
ImageJ Tutorial.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
OOP Languages: Java vs C++
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Introducing Java.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Table-Driven Acceptance Testing Mario Aquino Principal Software Engineer Object Computing, Inc.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Instructors begin using McGraw-Hill’s Homework Manager by creating a unique class Web site in the system. The Class Homepage becomes the entry point for.
Copyright  Hannu Laine C++-programming Part 3 Hannu Laine.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
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.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
C++ REVIEW – POINTERS AND TEST DRIVEN DEVELOPMENT.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
JUnit Don Braffitt Updated: 10-Jun-2011.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
Google C++ Testing Framework Test Fixtures: Using the Same Data Configuration for Multiple Tests.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Software Quality Assurance and Testing Fazal Rehman Shamil.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Perfecto Mobile Automation
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.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Software Engineering Lecture 11 Software Testing Presenter: Josef Hallberg 1.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Unit Testing.
Don Braffitt Updated: 26-Mar-2013
Testing Tutorial 7.
Andy Wang Object Oriented Programming in C++ COP 3330
Introduction to JUnit CS 4501 / 6501 Software Testing
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Overview of Memory Layout in C++
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
EEC-492/693/793 iPhone Application Development
CS 240 – Advanced Programming Concepts
C++ Constructor Insanity CSE 333 Summer 2018
SPL – PS1 Introduction to C++.
Presentation transcript:

Lec 24 Googletest - 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Lecture 24 Google C++ Framework 11/20/2013 1

Lec 24 Googletest - 2 CSCE 747 Fall 2013 Last Time  Jenkins Today  Google C++ Testing Framework (Google Test)  Test 2 1.TDD 2.Maven vs Ant 3.Hamcrest 4.WebDriver 5.Jenkins  Testing C with Google Test

Lec 24 Googletest - 3 CSCE 747 Fall 2013 References  googletest\ googletest   Download tab  Wiki – papers, tutorials etc.  Presentation Slides (Link on left)  Testing C (link on left).seleniumhq.org/docs/04_webdriver_advanced.jsp

Lec 24 Googletest - 4 CSCE 747 Fall 2013 Test 2 Question 1 Test Driven Design - Recall TA assignment: a.Time – number of seconds from start of week b.Meeting time – c.Course – List of Meeting times Sequence of Behavior - User Stories  Develop user stories (to confirm correct understanding with customer. In Agile this would be done with the customer)  Develop test cases,  then implement code to make the tests pass for the system behaviors

Lec 24 Googletest - 5 CSCE 747 Fall 2013 Test 2 Question 1 continued Sequence of Behavior - User Stories 1.Print time-of-day; print day-of-week 2.Does time1 intersect time2? 3.Print list of times of meetings associated with a course 4.Do two courses conflict, i.e. have any meetings that intersect? 5.Do any of the courses in which a TA is enrolled conflict with course1?  Required tools – only JUnit required

Lec 24 Googletest - 6 CSCE 747 Fall 2013 Test 2 Question 2 2.Investigate and write a ¾ to 1 page executive summary report of the what maven provides that ant does not.

Lec 24 Googletest - 7 CSCE 747 Fall 2013 Test 2 Question 3 - Hamcrest  Modify tests from question 1 to use at least three of the matchers supplied in Hamcrest.

Lec 24 Googletest - 8 CSCE 747 Fall 2013 Test 2 Question 4 - WebDriver Write a comprehensive test of the login to MySC that will upon any failure do a screen capture, and a source page capture and save them for a report.

Lec 24 Googletest - 9 CSCE 747 Fall 2013 Test 2 Question 5 - Jenkins Create a log/report of the installation and use of Jenkins.

Lec 24 Googletest - 10 CSCE 747 Fall 2013 Getting Started  After downloading Google Test, unpack it, read the README file and the documentation wiki pages vvvv

Lec 24 Googletest - 11 CSCE 747 Fall 2013 External links  Google Test talk slides Google Test talk slides  Testing with Google Test Testing with Google Test  Doc translations 玩转 Google 单元测试框架 Doc translations 玩转 Google 单元测试框架  Testing C with Google Test Testing C with Google Test  Testing embedded software Testing embedded software  Using Google Test in Xcode Using Google Test in Xcode  Code Coverage with Hudson Code Coverage with Hudson  ACCU talk slides & samples ACCU talk slides & samples  Setting up with VS 2008 Setting up with VS 2008

Lec 24 Googletest - 12 CSCE 747 Fall 2013 Google Test-related open source projects  Google Test UI is test runner that runs your test binary, allows you to track its progress via a progress bar, and displays a list of test failures. Clicking on one shows failure text. Google Test UI is written in C#. Google Test UI  GTest TAP Listener is an event listener for Google Test that implements the TAP protocol for test result output. If your test runner understands TAP, you may find it useful. GTest TAP ListenerTAP protocol

Lec 24 Googletest - 13 CSCE 747 Fall 2013 Wiki

Lec 24 Googletest - 14 CSCE 747 Fall 2013 V1_6_Primer Getting started with Google C++ Testing Framework Updated Apr 18, 2011 by  Introduction: Why Google C++ Testing Framework? Introduction: Why Google C++ Testing Framework?  Setting up a New Test Project Setting up a New Test Project  Basic Concepts Basic Concepts  Assertions Assertions  Basic Assertions Basic Assertions  Binary Comparison Binary Comparison  String Comparison String Comparison  Simple Tests Simple Tests  Test Fixtures: Using the Same Data Configuration for Multiple Tests Test Fixtures: Using the Same Data Configuration for Multiple Tests  Invoking the Tests Invoking the Tests  Writing the main() Function Writing the main() Function  Important note for Visual C++ users Important note for Visual C++ users  Where to Go from Here Where to Go from Here  Known Limitations Known Limitations

Lec 24 Googletest - 15 CSCE 747 Fall 2013 So what makes a good test: 1 1.Tests should be independent and repeatable.  It's a pain to debug a test that succeeds or fails as a result of other tests.  Google C++ Testing Framework isolates the tests by running each of them on a different object.  When a test fails, Google C++ Testing Framework allows you to run it in isolation for quick debugging

Lec 24 Googletest - 16 CSCE 747 Fall 2013 So what makes a good test: 2  Tests should be well organized and reflect the structure of the tested code.  Google C++ Testing Framework groups related tests into test cases that can share data and subroutines.  This common pattern is easy to recognize and makes tests easy to maintain.  Such consistency is especially helpful when people switch projects and start to work on a new code base

Lec 24 Googletest - 17 CSCE 747 Fall 2013 So what makes a good test: 3  Tests should be portable and reusable.  The open-source community has a lot of code that is platform-neutral, its tests should also be platform-neutral.  Google C++ Testing Framework works on different OSes, with different compilers  with or without exceptions, so Google C++ Testing Framework tests can easily work with a variety of configurations

Lec 24 Googletest - 18 CSCE 747 Fall 2013 So what makes a good test: 4  When tests fail, they should provide as much information about the problem as possible.  Google C++ Testing Framework doesn't stop at the first test failure. Instead, it only stops the current test and continues with the next.  You can also set up tests that report non-fatal failures after which the current test continues.  Thus, you can detect and fix multiple bugs in a single run-edit-compile cycle.

Lec 24 Googletest - 19 CSCE 747 Fall 2013 So what makes a good test: 5  The testing framework should liberate test writers from housekeeping chores and  let them focus on the test content.  Google C++ Testing Framework automatically keeps track of all tests defined, and  doesn't require the user to enumerate them in order to run them.

Lec 24 Googletest - 20 CSCE 747 Fall 2013 So what makes a good test: 6  Tests should be fast.  With Google C++ Testing Framework, you can reuse shared resources across tests and  pay for the set-up/tear-down only once, without making tests depend on each other.

Lec 24 Googletest - 21 CSCE 747 Fall 2013 Setting up a New Test Project

Lec 24 Googletest - 22 CSCE 747 Fall 2013 Basic Concepts  When using Google Test, you start by writing assertions, which are statements that check whether a condition is true. An assertion's result can be success, nonfatal failure, or fatal failure.  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.  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.

Lec 24 Googletest - 23 CSCE 747 Fall 2013 Assertions  Google Test assertions are macros that resemble function calls. You test a class or function by making assertions about its behavior.  ASSERT_* versions generate fatal failures when they fail, and abort the current function.  EXPECT_* versions generate nonfatal failures

Lec 24 Googletest - 24 CSCE 747 Fall 2013 custom failure messages with << ASSERT_EQ(x.size(), y.size()) << "Vectors x and y are of unequal length"; for (int i = 0; i < x.size(); ++i) { EXPECT_EQ(x[i], y[i]) << "Vectors x and y differ at index " << i; }

Lec 24 Googletest - 25 CSCE 747 Fall 2013 Binary Comparison

Lec 24 Googletest - 26 CSCE 747 Fall 2013 String Comparison  See also: For more string comparison tricks (substring, prefix, suffix, and regular expression matching, for example), see the Advanced Google Test Guide.Advanced Google Test Guide

Lec 24 Googletest - 27 CSCE 747 Fall 2013 Simple Tests  To create a test:  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.  TEST(test_case_name, test_name) {... test body... }

Lec 24 Googletest - 28 CSCE 747 Fall 2013 Testing Factorial // Tests factorial of 0. TEST(FactorialTest, HandlesZeroInput) { EXPECT_EQ(1, Factorial(0)); } // Tests factorial of positive numbers. TEST(FactorialTest, HandlesPositiveInput) { EXPECT_EQ(1, Factorial(1)); EXPECT_EQ(2, Factorial(2)); EXPECT_EQ(6, Factorial(3)); EXPECT_EQ(40320, Factorial(8)); }

Lec 24 Googletest - 29 CSCE 747 Fall 2013 Test Fixtures  Test Fixtures: Using the Same Data Configuration for Multiple Tests  To create a fixture, just: 1.Derive a class from ::testing::Test. Start its body with protected: or public: as we'll want to access fixture members from sub- classes. 2.Inside the class, declare any objects you plan to use. 3.If necessary, write a default constructor or SetUp() function to prepare the objects for each test.  A common mistake is to spell SetUp() as Setup() with a small u - don't let that happen to you. 4.If necessary, write a destructor or TearDown() function to release any resources you allocated in SetUp(). 5.If needed, define subroutines for your tests to share.

Lec 24 Googletest - 30 CSCE 747 Fall 2013  When using a fixture, use TEST_F() instead of TEST() as it allows you to access objects and subroutines in the test fixture:

Lec 24 Googletest - 31 CSCE 747 Fall 2013  For each test defined with TEST_F(), Google Test will: 1.Create a fresh test fixture at runtime 2.Immediately initialize it via SetUp(), 3.Run the test 4.Clean up by calling TearDown() 5.Delete the test fixture. Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one.  Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests.

Lec 24 Googletest - 32 CSCE 747 Fall 2013 tests for a FIFO queue class  interface template // E is the element type. class Queue { public: Queue(); void Enqueue(const E& element); E* Dequeue(); // Returns NULL if the queue is empty. size_t size() const;... };

Lec 24 Googletest - 33 CSCE 747 Fall 2013 a fixture class QueueTest : public ::testing::Test { protected: virtual void SetUp() { q1_.Enqueue(1); q2_.Enqueue(2); q2_.Enqueue(3); } // virtual void TearDown() {} Queue q0_; Queue q1_; Queue q2_; };

Lec 24 Googletest - 34 CSCE 747 Fall 2013 TEST_F(QueueTest, IsEmptyInitially) { EXPECT_EQ(0, q0_.size()); } TEST_F(QueueTest, DequeueWorks) { int* n = q0_.Dequeue(); EXPECT_EQ(NULL, n); n = q1_.Dequeue(); ASSERT_TRUE(n != NULL); EXPECT_EQ(1, *n); EXPECT_EQ(0, q1_.size()); delete n; n = q2_.Dequeue(); ASSERT_TRUE(n != NULL); EXPECT_EQ(2, *n); EXPECT_EQ(1, q2_.size()); delete n; }

Lec 24 Googletest - 35 CSCE 747 Fall 2013 Writing the main() Function #include "this/package/foo.h" #include "gtest/gtest.h" namespace { // The fixture for testing class Foo. class FooTest : public ::testing::Test { protected: // You can remove any or all of the following functions if its body // is empty. FooTest() { // You can do set-up work for each test here. }

Lec 24 Googletest - 36 CSCE 747 Fall 2013 virtual ~FooTest() { // You can do clean-up work that doesn't throw exceptions here. } // If the constructor and destructor are not enough for setting up // and cleaning up each test, you can define the following methods: virtual void SetUp() { // Code here will be called immediately after the constructor (right // before each test). } virtual void TearDown() { // Code here will be called immediately after each test (right // before the destructor). }

Lec 24 Googletest - 37 CSCE 747 Fall 2013 // Tests that the Foo::Bar() method does Abc. TEST_F(FooTest, MethodBarDoesAbc) { const string input_filepath = "this/package/testdata/myinputfile.dat"; const string output_filepath = "this/package/testdata/myoutputfile.dat"; Foo f; EXPECT_EQ(0, f.Bar(input_filepath, output_filepath)); } // Tests that Foo does Xyz. TEST_F(FooTest, DoesXyz) { // Exercises the Xyz feature of Foo. } } // namespace int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }

Lec 24 Googletest - 38 CSCE 747 Fall 2013 Samples  Sample #1 shows the basic steps of using Google Test to test C++ functions. Sample #1  Sample #2 shows a more complex unit test for a class with multiple member functions. Sample #2  Sample #3 uses a test fixture. Sample #3  Sample #4 is another basic example of using Google Test. Sample #4  Sample #5 teaches how to reuse a test fixture in multiple test cases by deriving sub-fixtures from it. Sample #5  Sample #6 demonstrates type-parameterized tests. Sample #6  Sample #7 teaches the basics of value-parameterized tests. Sample #7  Sample #8 shows using Combine() in value-parameterized tests. Sample #8  Sample #9 shows use of the listener API to modify Google Test's console output and the use of its reflection API to inspect test results. Sample #9  Sample #10 shows use of the listener API to implement a primitive memory leak checker. Sample #10

Lec 24 Googletest - 39 CSCE 747 Fall 2013  V1_6_AdvancedGuide Advanced topics on using Google C++ Testing Framework

Lec 24 Googletest - 40 CSCE 747 Fall 2013

Lec 24 Googletest - 41 CSCE 747 Fall 2013 How Google Tests Software 1.Google Software testing 2.Software Engineer in Test 3.The Test Engineer 4.Test Engr. Manager 5.Improving how Google tests Software A.Appendix A: Chrome OS Test Plan B.Appendix B: Test Tours for Chrome C.Appendix C: Blog Posts on Tools and Code

Lec 24 Googletest - 42 CSCE 747 Fall 2013 Download  gtest zip Sept 18, 2013

Lec 24 Googletest - 43 CSCE 747 Fall 2013 Gtest  IBM – tutorial  Testing C