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

update unit testing slide

parent d3072fe1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -127,7 +127,7 @@ McMaster University\\ }
\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{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.}
......@@ -291,8 +291,7 @@ class TestCircles:
\end{itemize}
\item{By default, \texttt{approx} considers numbers within a relative tolerance of 1e-6 of its expected value to be equal. }
\item{By default, \texttt{approx} considers numbers within a relative tolerance of 1e-6 and absolute tolerance of 1e-12 of its expected value to be equal. }
\end{itemize}
\begin{lstlisting}[language=Python, escapechar=!]
>>> 1.0001 == approx(1)
......@@ -304,7 +303,6 @@ True
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Redundant code in tests}
\begin{lstlisting}[language=Python, escapechar=!]
......@@ -319,7 +317,7 @@ class TestCircles:
def test_xcoord_are_not_equal(self):
!\colorbox{yellow}{circle = CircleT(1,2,3)}!
assert circle.xcoord() != 1
assert not circle.xcoord() == 1
\end{lstlisting}
\end{frame}
......@@ -341,7 +339,7 @@ class TestCircles:
assert self.circle.xcoord() == 1
def test_xcoord_are_not_equal(self):
assert self.circle.xcoord() != 2
assert not self.circle.xcoord() == 2
\end{lstlisting}
\end{frame}
......@@ -369,41 +367,6 @@ class TestCircles:
\end{frame}
% -----------------------------------------------------
\section{Code Coverage}
% -----------------------------------------------------
\begin{frame}[fragile]
\frametitle{How much should I test?}
\begin{itemize}
\item {Test all requirements in each function}
\item{Cover edge cases that may cause unintended consequences}
\item{Have an acceptable amount of
\href{https://en.wikipedia.org/wiki/Code_coverage}{code coverage}}
\item{Code coverage will be covered in more detail in future lectures}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Code Coverage}
\begin{itemize}
\item{Function coverage: has each function (or subroutine) in the program been called?}
\item{Statement coverage: has each statement in the program been executed?}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Code Coverage}
\begin{itemize}
\item{Branch coverage: has each branch of each control structure (such as in if and case statements) been executed?}
\begin{itemize}
\item{For example, given an if statement, have both the true and false branches been executed?}
\item{Another way of saying this is, has every edge in the program been executed?}
\end{itemize}
\item{Condition coverage (or predicate coverage): has each Boolean sub-expression evaluated both to true and false?}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Asserting about exceptions}
\begin{itemize}
......@@ -415,8 +378,8 @@ class TestCircles:
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
1 / 0
with pytest.raises(ZeroDivisionError):
1 / 0
\end{lstlisting}
\end{frame}
......@@ -444,6 +407,42 @@ def test_zero_division():
\end{frame}
% -----------------------------------------------------
\section{Code Coverage}
% -----------------------------------------------------
\begin{frame}[fragile]
\frametitle{How much should I test?}
\begin{itemize}
\item {Test all requirements in each function}
\item{Cover edge cases that may cause unintended consequences}
\item{Have an acceptable amount of
\href{https://en.wikipedia.org/wiki/Code_coverage}{code coverage}}
\item{Code coverage will be covered in more detail in future lectures}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Code Coverage}
\begin{itemize}
\item{Function coverage: has each function (or subroutine) in the program been called?}
\item{Statement coverage: has each statement in the program been executed?}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Code Coverage}
\begin{itemize}
\item{Branch coverage: has each branch of each control structure (such as in if and case statements) been executed?}
\begin{itemize}
\item{For example, given an if statement, have both the true and false branches been executed?}
\item{Another way of saying this is, has every edge in the program been executed?}
\end{itemize}
\item{Condition coverage (or predicate coverage): has each Boolean sub-expression evaluated both to true and false?}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Pytest plugin for measuring coverage}
\begin{itemize}
......
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