Skip to content
Snippets Groups Projects
Commit 7723dc42 authored by alicj's avatar alicj
Browse files

add WIP T05 slide

parent 4a403c5f
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
% Define Document Class
% Class Options Include:
% notes, notesonly, handout, trans,
% hidesubsections, shadesubsections,
% inrow, blue, red, grey, brown
%--------------------------------------------------------------------------
\documentclass[xcolor=dvipsnames, shownotes, colorlinks]{beamer}
%--------------------------------------------------------------------------
% -------------------------------------------------------------------------
% Define Package Theme
%--------------------------------------------------------------------------
\usepackage{color}
\usepackage[T1]{fontenc}
%% \usepackage{fix-cm}
\usepackage{hyperref}
\hypersetup{
urlcolor=cyan,
linkcolor=white
}
\usepackage{subfigure}
\usepackage{graphicx}
\graphicspath{ {/} }
\usepackage{enumerate}
\usetheme{Antibes}
\setbeamertemplate{sidebar}[right]
\setbeamertemplate{caption}[numbered]
\usepackage{listings} % Code formatting
\usepackage{lstautogobble}
\usepackage{dirtytalk}
\lstset{
language=[LaTeX]TeX,
basicstyle=\ttfamily\scriptsize,
tabsize=2,
breaklines=true,
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
showstringspaces=true,
showspaces=false,
keywordstyle=\color{blue},
stringstyle=\color{magenta},
commentstyle=\color{ForestGreen},
morekeywords={maketitle, tableofcontents, subsection, subsubsection, includegraphics, toprule, midrule, bottomrule},
autogobble=true
}
%------------------------------------------------------------------------------
% Commands
%------------------------------------------------------------------------------
\newcommand*\oldmacro{}%
\let\oldmacro\insertshorttitle%
\renewcommand*\insertshorttitle{%
\oldmacro\hfill%
\insertframenumber\,/\,\inserttotalframenumber}
% Figure Source
\usepackage[absolute,overlay]{textpos}
\setbeamercolor{framesource}{fg=gray}
\setbeamerfont{framesource}{size=\tiny}
\newcommand{\source}[1]{\begin{textblock*}{\paperwidth}(-5pt,\textheight)
\begin{beamercolorbox}[ht=0.5cm,right]{framesource}
\usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
\end{beamercolorbox}
\end{textblock*}}
%--------------------------------------------------------------------------
% Presentation Title Slide
%--------------------------------------------------------------------------
\title{Unit Testing - pytest}
\subtitle{CS 2ME3/SE 2AA4}
\author{Zichen Jiang\\
Owen Huyn}
\institute{Department of Computing and Software\\
McMaster University\\ }
\date{\today}
%--------------------------------------------------------------------------
% Document
% To add notes to the slides use: \note{}
% Add \section{} or \subsection{} for use in table of contents
%--------------------------------------------------------------------------
\begin{document}
% Create Title Slide
\begin{frame}
\maketitle
\end{frame}
\section[Outline]{}
% Create Table of Contents Slide - Outline
\begin{frame}
\frametitle{Outline}
{\hypersetup{linkcolor=black}
\tableofcontents
}
\end{frame}
% -----------------------------------------------------
\section{Introduction}
% -----------------------------------------------------
\begin{frame}[fragile]
\frametitle{What is Unit Testing}
\begin{itemize}
\item{Unit testing verifies that individual units of code (usually functions) work as intended}
\item{Designed to be \textbf{simple}, easy to write and run}
\item{You can test both from a blackbox perspective and a whitebox perspective}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Who writes unit tests}
\begin{itemize}
\item{Developers should test their own code!}
\item{The person who wrote the code usually has the best understanding of what their code does}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Why Unit Test?}
\begin{itemize}
\item{You can catch bugs much earlier}
\item{Provides documentation on a specific function}
\item{Helps developer improve the implementation design of a function}
\item{Every good developer should be a good tester too!\\
No one likes to work with someone who doesn't verify/test if their code works.}
\end{itemize}
\end{frame}
% -----------------------------------------------------
\section{pytest}
% -----------------------------------------------------
\begin{frame}[fragile]
\frametitle{What is pytest}
\begin{itemize}
\item{pytest is a framework that maeks it easy to write small tests}
\item{Similar to JUnit (Java), CppUnit (C++)}
\item{Knowledge is transferrable to another xUnit framework regardless of language}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Getting Started}
\begin{itemize}
\item{Installing pytest is very simple, simply run the following command in your command line}
\item{\texttt{pip install -U pytest }}
\item{For more information, visit \href{https://docs.pytest.org/en/latest/getting-started.html} {pytest Installation and Getting Started}}
\end{itemize}
\end{frame}
% -----------------------------------------------------
\section{Demo}
% -----------------------------------------------------
\begin{frame}[fragile]
\frametitle{Demo}
\begin{itemize}
\item{Let's get started, I encourage everyone to pull out their laptops and follow along.}
\item{We will test A1 from last year, which was introduced in the past tutorials}
\item{Don't be afraid to ask any questions!}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Create our first unit test file}
\begin{itemize}
\item{To start, create a new Python file in the same directory of our file that we want to test}
\item{You can do this from the command line or any text editor of your choiceDon't be afraid to ask any questions!}
\item{\texttt{echo $> >$ test\_circles.py}}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Create our first test template}
\begin{itemize}
\item{To start with our unit test, follow this template:}
\end{itemize}
\begin{lstlisting}[language=Python]
import pytest
class TestCircles:
\end{lstlisting}
\begin{enumerate}
\item{Import the pytest library}
\item{Write a unit testing class starting with the word \texttt{Test}}
\end{enumerate}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Assert?}
\begin{itemize}
\item{ Wikipedia: \say{... is a statement that a predicate (Boolean-valued function, i.e. a true-false expression) is expected to always be true at that point in the code. If an assertion evaluates to false at run time, an assertion failure results, which typically causes the program to crash, or to throw an assertion exception.}}
\item{Basically, if whatever follows assert is true, it will continue. Otherwise the test will fail and stop running.}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Writing our first test}
\begin{lstlisting}[language=Python]
import pytest
from CircleADT import *
class TestCircles:
def test_xcoord_are_equal(self):
circle = CircleT(1,2,3)
assert circle.xcoord() == 1
def test_xcoord_are_not_equal(self):
circle = CircleT(1,2,3)
assert (circle.xcoord() != 1) == False
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Running our first test}
\begin{itemize}
\item{Run this command in your command prompt inside the folder of your test file}
\item{\texttt{pytest test\_circles.py}}
\begin{figure}[b]
{\includegraphics[width=10cm]{test-result}}
\end{figure}
\end{itemize}
\end{frame}
\end{document}
Tutorials/T05-PyUnit/slides/circle1.png

15.7 KiB

Tutorials/T05-PyUnit/slides/circle2.png

24.2 KiB

Tutorials/T05-PyUnit/slides/test-result.png

36 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment