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

add code coverage slides

parent 714a6aa8
No related branches found
No related tags found
No related merge requests found
...@@ -30,3 +30,5 @@ cabal.config ...@@ -30,3 +30,5 @@ cabal.config
html html
latex latex
*.class *.class
.cache
.coverage
No preview for this file type
...@@ -367,6 +367,10 @@ class TestCircles: ...@@ -367,6 +367,10 @@ class TestCircles:
\end{itemize} \end{itemize}
\end{frame} \end{frame}
% -----------------------------------------------------
\section{Code Coverage}
% -----------------------------------------------------
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{How much should I test?} \frametitle{How much should I test?}
\begin{itemize} \begin{itemize}
...@@ -379,14 +383,41 @@ class TestCircles: ...@@ -379,14 +383,41 @@ class TestCircles:
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Code Coverage} \frametitle{Code Coverage}
\begin{itemize} \begin{itemize}
\item {} \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{itemize}
\end{frame} \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}
\item{\url{https://pypi.python.org/pypi/pytest-cov}}
\item{You can install it via pip: \texttt{pip install pytest-cov}}
\item{Then, in the source code directory, run \texttt{pytest --cov}}
\end{itemize}
\begin{figure}[b]
{\includegraphics[width=8cm]{test-coverage}}
\end{figure}
\end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Documentation on pytest} \frametitle{Documentation on pytest}
\begin{itemize} \begin{itemize}
\item {\url{https://docs.pytest.org/en/latest/xunit_setup.html}} \item {\url{https://docs.pytest.org/en/latest/xunit_setup.html}}
\item {\url{https://en.wikipedia.org/wiki/Code_coverage}}
\end{itemize} \end{itemize}
\end{frame} \end{frame}
......
Tutorials/T05-PyUnit/slides/test-coverage.png

249 KiB

import unittest import pytest
from Statistics import * from Statistics import *
class StatisticsTests(unittest.TestCase): class TestStatistics():
def setUp(self): def setup_method(self):
c1 = CircleT(1,0,2) c1 = CircleT(1,0,2)
c2 = CircleT(-3,-5,5.25) c2 = CircleT(-3,-5,5.25)
c3 = CircleT(-2,5,10) c3 = CircleT(-2,5,10)
...@@ -12,17 +12,14 @@ class StatisticsTests(unittest.TestCase): ...@@ -12,17 +12,14 @@ class StatisticsTests(unittest.TestCase):
self.circles = [c1,c2,c3,c4,c5] self.circles = [c1,c2,c3,c4,c5]
def tearDown(self): def teardown_method(self):
self.circles = None self.circles = None
def testAverageOfCircles(self): def testAverageOfCircles(self):
self.assertAlmostEqual(average(self.circles), 2000000003.45, None, None, 0.1) assert average(self.circles) == pytest.approx(2000000003.45, rel=0.1)
def test_rank(self): def test_rank(self):
self.assertTrue(rank(self.circles) == [4,3,2,5,1]) assert rank(self.circles) == [4,3,2,5,1]
def test_stdDev(self): def test_stdDev(self):
self.assertAlmostEqual(stdDev(self.circles), 3999999998.275, None, None, 0.1) assert stdDev(self.circles) == pytest.approx(3999999998.275, rel=0.1)
if __name__ == '__main__':
unittest.main()
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