A3 Redux.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Computer Science 209 Testing With JUnit. Why Test? I don ’ t have time, I ’ ve got a deadline to meet The more pressure I feel, the fewer tests I will.
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Testing by Duncan Butler Sara Stephens. Too much to cover.
Programming Languages WHY MORE? Wasn’t ONE ENOUGH? Introduction to CS260.
Unit testing C# classes “If it isn’t tested it doesn’t work” Unit testing C# classes1.
13-Jul-15 Test Suites. Test classes A unit test is a test of an individual class By convention, we name test classes after the class that is being tested.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Introducing Java.
Object Oriented Software Development
Multiple Choice Solutions True/False a c b e d   T F.
Introduction to Python
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
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.
Domain Model Classes and Objects Association Structure Requirement Specification Domain Model.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
11 Computers, C#, XNA, and You Session 1.1. Session Overview  Find out what computers are all about ...and what makes a great programmer  Discover.
1 A Very Brief Introduction to Relational Databases.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Software Engineering Lecture 11 Software Testing Presenter: Josef Hallberg 1.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
JavaScript: Conditionals contd.
COMP 2100 From Python to Java
Object-Oriented programming for Beginners LEAPS Computing 2015
C# Basic Syntax, Visual Studio, Console Input / Output
Top 8 Best Programming Languages To Learn
John D. McGregor Session 9 Testing Vocabulary
Key Ideas from day 1 slides
Introduction to JUnit CS 4501 / 6501 Software Testing
Agenda Warmup AP Exam Review: Litvin A2
C# and the .NET Framework
Haritha Dasari Josue Balandrano Coronel -
XNAT 1.7 DicomEdit 4, DicomEdit 6, and Mizer
Functions CIS 40 – Introduction to Programming in Python
Introduction to Methods in java
Lists in Python Parallel lists.
John D. McGregor Session 9 Testing Vocabulary
CS Programming I Jim Williams, PhD.
Unit testing C# classes
Quick Start Guide for Visual Studio 2010
TRANSLATORS AND IDEs Key Revision Points.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
John D. McGregor Session 9 Testing Vocabulary
Test-first development
Lesson 2: Building Blocks of Programming
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Learning to Program in Python
CIS16 Application Development – Programming with Visual Basic
LESSON 13 – INTRO TO ARRAYS
Introduction to JUnit CS 4501 / 6501 Software Testing
Teaching London Computing
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Coding Concepts (Data Structures)
Computer Science Testing.
Repetition Structures
Programming Languages
Python 19 Mr. Husch.
What is Programming Language
Python 19 Mr. Husch.
CISC101 Reminders Assignment 3 due today.
Corresponds with Chapter 5
Presentation transcript:

A3 Redux

Learning Objectives By now, you should be able to: Conceptually group tests into set. Design automated unit tests for those tests Learn how to operate automated unit testing machinery within an IDE (Visual Studio)

Learning Objectives By now, you should be able to: Conceptually group tests into set. Design automated unit tests for those tests Learn how to operate automated unit testing machinery within an IDE (Visual Studio)

Automated Unit/Integration Testing What constitutes a “unit”? Depends a bit on your perspective. In some ways, this assignment is about integration testing (do all these pieces fit together and work?); however, in the real world, the VendingMachine might frequently be considered a “unit.” Regardless, the testing proceeds similarly: [define preconditions] [execute some behaviours] [check if expected values match actual values]

What was annoying Extracting (and comparing) things from delivery chute Extracting (and comparing) things from the vending machine A lot of code/repetition

Extracting and Checking A3 solution was a bit dumb A4 shell is a bit more elegant         public static Tuple<int, string[]> ExtractDelivery(HardwareFacade hardware) {             var items = hardware.DeliveryChute.RemoveItems();             var cents = items.OfType<Coin>().Sum(coin => coin.Value.Value);             var products = items.OfType<Product>().Select(product => product.Name).ToArray();                           return new Tuple<int, string[]>(cents, products);         }         public static void CheckDelivery(Tuple<int, string[]> delivery, int cents, string[] productNames) {             Assert.AreEqual(cents, delivery.Item1);             Assert.IsTrue(productNames.SequenceEqual(delivery.Item2));         }             var delivery = VMUtility.ExtractDelivery(this.hardware);               VMUtility.CheckDelivery(delivery, 0, new string[] { "Coke" }); or             CheckDelivery(ExtractDelivery(this.hardware), 0, new string[] { "Coke" });

Aside: API Usability Think about how you want someone to be using your code (or, how you want to use your code): What is the “language” you want them to use? What are the verbs/nouns that should be here? What is the language that the “user” of your API is thinking of? How much should they need to know to use this? Do they need to know about the abstractions you’re using? Could someone reading the code understand what was going on (without digging into the code)? What is the order they will be thinking of things in?             CheckDelivery(ExtractDelivery(this.hardware), 0, new string[] { "Coke" });

Lots of Code Writing unit tests is a way of expressing how you think the system ought to work (it’s actually a lot like a spec in this sense!) Remember: when we were in the midst of doing A2, someone in the class asked, “Can we just have the scripts you’ll be testing our code on?” Test-driven development: Writing the test cases first(!), and then moving towards writing the code that you need (to make the code work)

“Modularizing” Test Code [define preconditions] [execute some behaviours] [check if expected values match actual values] The preconditions were often similar/common across multiple tests. In the VS Testing framework, you could have used the [TestInitialize] attribute to say, “Execute this each time before each test”

“Modularizing” Test Code You can also group by “related” tests: T08-good-approximate-change T09-good-hard-for-change All the U*tests

Unit Testing Frameworks are Similar VS Unit Testing == NUnit (C#) == JUnit (Java) == Python unit test Syntax is slightly different, but the core flow is basically the same (spec preconditions, do stuff, compare expected to actual values) Running also sometimes differ: through IDE, command line, separate GUI

JUnit

Python Unit Testing https://jeffknupp.com/blog/2013/12/09/improve-your-python-understanding-unit-testing/ https://docs.python.org/2/library/unittest.html

Python Unit Testing

GUI vs. Command Line

GUI vs. Command Line

A3 Learning You now know how to do simple unit testing Remember to use these powers for the forces of good