Unit Testing LEVEL GAME. https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks  Syntax varies based on framework  TDD goals are the same regardless.

Slides:



Advertisements
Similar presentations
Software Testing Technique. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves.
Advertisements

TRUTH TABLES Section 1.3.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 11 Instructor Paulo Alencar.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
Testing an individual module
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Software Testing (Part 2)
Introduction Telerik Software Academy Software Quality Assurance.
CMSC 345 Fall 2000 Unit Testing. The testing process.
1 Phase Testing. \ 2 Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine subphases) Define Coding Standards.
Agenda Introduction Overview of White-box testing Basis path testing
Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Black-box Testing.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Unit Testing LEVEL GAME.  Create pieces array  Call move or interact  Use getters or return type to verify correct behavior  Test ends (don’t go GameEngine.BOARD_SIZE-1)
Black Box Testing : The technique of testing without having any knowledge of the interior workings of the application is Black Box testing. The tester.
Software Testing White Box Testing. Agenda What is White Box Testing Correctness Tests and Path Coverage Correctness Tests and Line Coverage McCabe Cyclomatic.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
Testing Integral part of the software development process.
Metrics of Software Quality
Testing Verification and the Joy of Breaking Code
Software Testing.
White-Box Testing Pfleeger, S. Software Engineering Theory and Practice 2nd Edition. Prentice Hall, Ghezzi, C. et al., Fundamentals of Software Engineering.
John D. McGregor Session 9 Testing Vocabulary
Software Engineering (CSI 321)
CompSci 230 Software Construction
Recall The Team Skills Analyzing the Problem
Chapter 13 & 14 Software Testing Strategies and Techniques
Data Coverage and Code Coverage
Structural testing, Path Testing
WHITEBOX TESTING APPROACH
Types of Testing Visit to more Learning Resources.
John D. McGregor Session 9 Testing Vocabulary
Lesson 9: "if-else-if" and Conditional Logic
CHAPTER 4 Test Design Techniques
Boolean logic Taken from notes by Dr. Neil Moore
UNIT-4 BLACKBOX AND WHITEBOX TESTING
John D. McGregor Session 9 Testing Vocabulary
Chapter 14 Software Testing Techniques
“White box” or “glass box” tests
Static Testing Static testing refers to testing that takes place without Execution - examining and reviewing it. Dynamic Testing Dynamic testing is what.
CS240: Advanced Programming Concepts
CSE 403 Lecture 13 Black/White-Box Testing Reading:
CSE 303 Concepts and Tools for Software Development
Chapter 10 – Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
White-Box Testing Techniques I
Control Structure Testing
CSE403 Software Engineering Autumn 2000 More Testing
Boolean logic Taken from notes by Dr. Neil Moore
CSE 1020:Software Development
TYPES OF TESTING.
UNIT TESTING TOOLS Workshop on Integrating Software
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing.
08120: Programming 2: SoftwareTesting and Debugging
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Unit Testing LEVEL GAME

 Syntax varies based on framework  TDD goals are the same regardless of language  Approach to unit testing (e.g., what to test) is same/similar for various languages UNIT TESTING IS NOT JUST JAVA

BLACK BOX VS WHITE BOX CriteriaBlack Box TestingWhite Box Testing Definition Black Box Testing is a software testing method in which the internal structure/ design/ implementation of the item being tested is NOT known to the tester White Box Testing is a software testing method in which the internal structure/ design/ implementation of the item being tested is known to the tester. Levels Applicable To Mainly applicable to higher levels of testing: Acceptance Testing System Testing Mainly applicable to lower levels of testing: Unit Testing Integration Testing ResponsibilityGenerally, independent Software TestersGenerally, Software Developers Programming Knowledge Not RequiredRequired Implementation Knowledge Not RequiredRequired Basis for Test Cases Requirement SpecificationsDetail Design From:

WHAT TO TEST

 Create pieces array  Call interact  Use getters or return type to verify correct behavior  If interact with adjoining piece, put that piece & yours on board  If interact within range, be sure to test locations within range PLUS one beyond TEST INTERACTION

 Create pieces array  Call move  Use getters or return type to verify correct behavior  Test ends (don’t go GameEngine.BOARD_SIZE-1) TEST MOTION

 Can’t test random behavior deterministically  Need to run method multiple times  Do all possible results actually occur?  Do the possible results account for ALL results? (i.e., no invalid moves)  What if LOTS of valid results? (e.g., any location)  Test ends  Identify “categories” of possibilities  If limited number of possibilities, test each one  E.g., move one to right or left TEST RANDOM MOVEMENT

 What if the player is within “range” of more than one piece?  We’re not testing this, but the approach would be:  Create a GameEngine  Create a pieces array  Add a setter to GameEngine for the pieces array  Call interaction  This would not be in the scope of unit testing pieces. This might be a unit test for the GameEngine. BUT, tests need to run quickly. Can’t test every scenario. TEST MULTIPLE INTERACTION

EMMA TEST COVERAGE

  Not required for 306, but useful tool (some companies strive for close to 100% test coverage)  Run the tests, see what parts of your code were/were not tested EMMA CODE COVERAGE

SNIPER INTERACT COVERED Entire interact method was tested

DOORMAT NOT COVERED - OK move method of RandomMotionPiece and Minion not covered – shouldn’t be other move-related (e.g., setLocation) not covered – shouldn’t be interact method of Minion not covered. oops always returns NONE. Do we need to test? Yes, if this is the spec. Because if someone changes that, tests will capture. LevelEngine not covered – shouldn’t be

PRIZE PARTIALLY COVERED yellow: 1 of 4 branches missed Why? my tests are only for location, don’t test if prize already won (first row) same location prize Won true false true false

TYPO IN TEST oops, this should be i=11 (kangalo is at location 10)

AN EXAMPLE

 How much of your code are you actually testing?  coverage-vs-branch-coverage.html coverage-vs-branch-coverage.html public static int doSomething(int x, int y, int z) { int val = 100; if (x > y) val += 10; if (x < z) val += 20; if (z > 20) val += 100; return va l; }  How to address? (on your own)  and-path-coverage-testing-in-java.html and-path-coverage-testing-in-java.html TEST COVERAGE (WHITE BOX) Quick: w/o looking at next slide, what tests would you write for this? Write down values for x, y and z (plus return value). Turn this in for class participation credit

PATH COVERAGE Condition 1: x > y Condition 2: x < z Condition 3: z > XYZ123Result TTT > 1020 < 3030 > TTF > 1015 < 1818 > TFT > 2030 < 2525 > TFF > 2020 < 1515 > FTT > 5015 < 2525 > FTF > 5010 < 2515 > FFT > 5030 < 2525 > FFF > 5030 < 2515 > 20100

UNIT public void pathTest() { assertEquals(230, TestCoverage.doSomething(20, 10, 30)); assertEquals(130, TestCoverage.doSomething(15, 10, 18)); assertEquals(210, TestCoverage.doSomething(30, 20, 25)); assertEquals(110, TestCoverage.doSomething(30, 20, 15)); assertEquals(220, TestCoverage.doSomething(15, 50, 25)); assertEquals(120, TestCoverage.doSomething(10, 50, 15)); assertEquals(200, TestCoverage.doSomething(30, 50, 25)); assertEquals(100, TestCoverage.doSomething(30, 50, 15)); }

SIDEBAR: CYCLOMATIC COMPLEXITY  Based on linearly independent paths Condition 1: x > y Condition 2: x < z Condition 3: z > XYZ123Result TTT > 1020 < 3030 > TTF > 1015 < 1818 > TFT > 2030 < 2525 > FTT > 5015 < 2525 > and-path-coverage-testing-in-java.html

The cyclomatic complexity of a section of source code is the number of linearly independent paths within it.  For instance, if the source code contained no control flow statements (conditionals or decision points), the complexity would be 1, since there would be only a single path through the code.  If the code had one single-condition IF statement, there would be two paths through the code: one where the IF statement evaluates to TRUE and another one where it evaluates to FALSE, so the complexity would be 2.  Two nested single-condition IFs, or one IF with two conditions, would produce a complexity of 4. SIDEBAR CC CONTINUED

 Cyclomatic complexity is determined by drawing a control flow graph. It’s different from path coverage because you don’t test all combinations. In this example, there are 3 independent if statements. So cyclomatic complexity is 6. But there are 8 possible paths. So path coverage requires 8. SIDEBAR CC CONTINUED

 Method to test all the possible discrete combinations of the parameters involved.  SIDEBAR 2: ALL PAIRS TESTING