Lab 6: Testing. Software Studio DataLab, CS, NTHU

Similar documents
Step 1: Setup a Gitlab account

Full Stack boot camp

Chapter 1 - Development Setup of Angular

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

Lab 01 How to Survive & Introduction to Git. Web Programming DataLab, CS, NTHU

Arjen de Blok. Senior Technical Consultant bij ICT Groep ( sinds 1995 Programmeren sinds 1990 Technologiën. Links

Getting Started with ReactJS

Web Development for Dinosaurs An Introduction to Modern Web Development

Deep Dive on How ArcGIS API for JavaScript Widgets Were Built

Modern and Responsive Mobile-enabled Web Applications

Advance Mobile& Web Application development using Angular and Native Script

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Uninstall A Apps Windows 8 Programming Using Html5 Jump Start

Finally JavaScript Is Easy, with Oracle JET! Geertjan Wielenga Product Manager Oracle Developer Tools

JavaScript and MVC Frameworks FRONT-END ENGINEERING

Webpack. What is Webpack? APPENDIX A. n n n

End-to-End Test and Build

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

Cisco Spark Widgets Technical drill down

Project Plan Optimizing Car Dealership Inventory

Introduction to Using NPM scripts as a Build Tool. 1. 1

Production Registration System 2.0

Introduction to Git. Database Systems DataLab, CS, NTHU Spring, 2018

55249: Developing with the SharePoint Framework Duration: 05 days

APACHE SLING & FRIENDS TECH MEETUP SEPTEMBER Integrating a Modern Frontend Setup with AEM Natalia Venditto, Netcentric

Comprehensive AngularJS Programming (5 Days)

Salvatore Rinzivillo VISUAL ANALYTICS

Getting started with Tabris.js Tutorial Ebook

Practical Node.js. Building Real-World Scalable Web Apps. Apress* Azat Mardan

The Visual Studio 2015 Checklist

Course 55197A: Microsoft SharePoint Server 2016 for the Site Owner/Power User

Create Open Data with Google Analytics. Open Data Day 2019

JavaScript on the Command Line & PRATIK PATEL CTO TripLingo Labs

npm install [<name> [<name>...]] [--save --save-dev --save-optional]

Lab 1 - Introduction to Angular

CodeHub. Curran Kelleher 8/18/2012

How to use jquery file. How to use jquery file.zip

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

Tools. SWE 432, Fall Design and Implementation of Software for the Web

Webpack 2 The last bundler you would need in Vijay Dharap, Principal Architect, Infosys

React(.js) the Domino Way High-Performance Client for Domino. Knut Herrmann

1) Log on to the computer using your PU net ID and password.

WEB DEVELOPER BLUEPRINT

AngularJS Intro Homework

Lab 08. Command Line and Git

Lab Objective. Lab Assignment. Downloads and Installation

"Charting the Course... MOC A: Developing with the SharePoint Framework. Course Summary

CICD pipeline for your extensions with Visual Studio Team Services

Angular 2 Programming

One Framework. Angular

webpack bundle inner structure and optimization Alexey Ivanov, Evil Martians

JavaScript Fundamentals_

5th April Installation Manual. Department of Computing and Networking Software Development Degree

Is your JavaScript ready for the Enterprise? What does that even mean?

The Move from Raster Tiles to Vector Tiles. Two Architectures for Making Lots of Maps Dynamically

ArcGIS API for JavaScript: Getting Started Andy René

DOWNLOAD OR READ : ANSWERHUB GITHUB PDF EBOOK EPUB MOBI

WorldSpace Attest Quick Start Guide

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

State Management and Redux. Shan-Hung Wu & DataLab CS, NTHU

SEEM4570 System Design and Implementation. Lecture 4 AJAX and Demo

Turbo boost your digital app test automation with Jenkins

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Spark SDK Video - Overview and Coding Demo

Agile Web Development with Rails 5.1

Quick Desktop Application Development Using Electron

We are assuming you have node installed!

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

MOdern Java(Script) Server Stack

Introduction. Martin Ledvinka. Winter Term 2018

research assistant at VSE/LEE course site: janvavra.github.io consultations by appointment

Guides SDL Server Documentation Document current as of 04/06/ :35 PM.

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

IBM Image-Analysis Node.js

Sawmill TECH TIPS help for Web, Security, & Data Professionals

INF5750. Introduction to JavaScript and Node.js

"Charting the Course... Comprehensive Angular. Course Summary

Experimental Psychology Lab Practice tidy cooperation

30 th September 2017 Milan

Ionic Tutorial. For Cross Platform Mobile Software Development

Server execution of JavaScript: What could possibly go wrong?

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

Testing & Performance. SWE 432, Fall 2016 Design and Implementation of Software for the Web

csc444h:& so(ware&engineering&i&

Learn Gulp. Jonathan Birkholz. This book is for sale at This version was published on

20480C: Programming in HTML5 with JavaScript and CSS3. Course Code: 20480C; Duration: 5 days; Instructor-led. JavaScript code.

To Kill a Monolith: Slaying the Demons of a Monolith with Node.js Microservices on CloudFoundry. Tony Erwin,

Index. Elad Elrom 2016 E. Elrom, Pro MEAN Stack Development, DOI /

3 Continuous Integration 3. Automated system finding bugs is better than people

There are several formatting conventions used in this document. Please take note of the formatting styles:

Philosophy of Unit Testing

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 11, 2017

Continuous Integration (CI) with Jenkins

CSC207 Week 4. Larry Zhang

Version Control with Git ME 461 Fall 2018

AEM React. History. 1 Introduction. AEM components written in React. Why React and AEM? Features. Projects. date author message changed chapters

Getting Started With NodeJS Feature Flags

Guides SDL Server Documentation Document current as of 05/24/ :13 PM.

Introduction to Benchmark. Database Systems DataLab, CS, NTHU Spring, 2018

Overview of BC Learning Network SMS2 Introduction

Transcription:

Lab 6: Testing Software Studio DataLab, CS, NTHU

Notice This lab is about software development good practices Interesting for those who like software development and want to go deeper Good to optimize your development time

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

What is testing? Is it important?

Actually, we are always doing some kind of testing..

And expecting some result..

And expecting some result..

Sometimes we just open our app and start clicking to see results

Why test like a machine? We can write programs to automatically test our application!

Most common type of test: Unit test

Unit test Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application. - Wikipedia

Good unit test properties It should be automated and repeatable It should be easy to implement Once it s written, it should remain for future use Anyone should be able to run it It should run at the push of a button It should run quickly The art of Unit Testing, Roy Osherove

Many frameworks for unit tests in several languages

Common procedure Assertion: A statement that a predicate is expected to always be true at that point in the code. -Wikipedia

Common procedure We write our application and want it to do something, so we write a test to see if it s behaving as we expect

Common procedure Pseudocode:

But how to do that in JS?

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Simple testing: expect library and jsbin

Test passed:

Test didn t pass:

This is ok for testing some simple functions.. But what about our React app?

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Karma Karma is a JavaScript test runner created by the AngularJS team. Karma uses your test framework to run tests in various environments of your choice

Karma Karma has several configurations for our tests and can run code using several JS testing frameworks such as Mocha, Jasmine and QUnit

Karma Karma has several configurations for our tests and can run code using several JS testing frameworks such as Mocha, Jasmine and QUnit For this lab, we are going to focus on Mocha

Mocha framework Mocha is a JavaScript test framework featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library

Karma + Mocha Use Karma to configure tests for application Use Mocha framework tools to write the tests Use Karma to run the tests

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Configuring Karma First, install required dependencies:

Configuring Karma Create config file for Karma named karma.config.js same folder as package.json and webpack.config.js

Configuring Karma Create config file for Karma named karma.conf.js same folder as package.json and webpack.config.js

Configuring Karma In package.json, change the script for test with karma start

Configuring Karma If you are having problems with the tests, it might be cached code To solve this, inside webpack.config.js, modify plugins:

Configuring Karma CommonChunks is a feature from webpack that caches code in chunks for faster reloading

Configuring Karma Create folder src/tests where our test files will be

Configuring Karma To test the Main.jsx component, we create a Main.test.jsx file in that folder

Configuring Karma For other components that we want to test, we create similar files inside the tests folder

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Karma demo: Simple test Inside Main.test.jsx:

Karma demo: Simple test Run tests on terminal with npm test Output:

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Karma demo: Weather mood We can write tests for the components of the weather app Example: Today.test.jsx

Karma demo: Weather mood Test if today component exists:

Karma demo: Weather mood Test if today component renders default city:

Karma demo: Weather mood Test if today component renders non default city:

Karma demo: Weather mood Test if today component renders metric unit:

Karma demo: Weather mood Output of tests:

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Karma demo: Timer App

Karma demo: Timer App

Karma demo: Timer App

Karma demo: Timer App What can we test in this app?

Karma demo: Timer App Test if seconds are rendered correctly

Karma demo: Timer App Test if seconds are rendered correctly

Karma demo: Timer App Rendering of controls

Karma demo: Timer App Check if app functionalities are working (start/stop)

Karma demo: Timer App Countdown functions (remember errors countdown from nightmare mode in color game?)

Outline Introduction to Testing Simple testing in JS Testing with Karma Configuring Karma Karma demo: Simple test Karma demo: Weather Mood Karma demo: Timer App Conclusions

Conclusions For this lab we used Karma runner with Mocha, but you could try other testing frameworks For each new language you learn there are testing frameworks that you can use to automate this work and reduce errors We are humans and sometimes we can forget to test something manually, it s better to let your testing framework do this work for you

Today s mission Clone the Weather Mood repository and explore the written tests Clone the Timer App repository and explore the written tests Try writing tests for these applications or your own application Optional assignment!

Optional assignment Bonus 10 points for those who want it This assignment will be due in 1 week (04-13) at 23:59

Optional assignment Create a fork for the hello-react repository Create at least 1 test for this project Not just expect(1).tobe(1) Not just expect().toexist() Actually test some component (Try to test some function)

Optional assignment The created tests must run correctly Submit your merge request

References Karma Mocha Karma Tutorial - Unit Testing JavaScript Client side testing with Karma and Mocha