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

update unit testing slides with exceptions resolve issue #41

parent 235ccac1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -304,6 +304,7 @@ True
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Redundant code in tests}
\begin{lstlisting}[language=Python, escapechar=!]
......@@ -402,6 +403,47 @@ class TestCircles:
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Asserting about exceptions}
\begin{itemize}
\item{It is very important in unit testing to check for edge cases and behaviour in the case of unexpected input.}
\item{If a function raises an exception in some cases, you should include those cases in your unit testing as well.}
\item{You can do so by using a context manager called pytest.raises.}
\end{itemize}
\begin{lstlisting}[language=Python, escapechar=!]
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
1 / 0
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Asserting about exceptions}
\begin{itemize}
\item{If an exception is not raised in a pytest.raises block, the test will fail.}
\end{itemize}
\begin{lstlisting}[language=Python, escapechar=!]
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
2 / 1
\end{lstlisting}
\begin{itemize}
\item{If you run this test, it will give the result:}
\end{itemize}
\begin{figure}[b]
{\includegraphics[width=8cm]{exception-not-raised}}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Pytest plugin for measuring coverage}
\begin{itemize}
......@@ -433,8 +475,9 @@ class TestCircles:
\begin{frame}[fragile]
\frametitle{References}
\begin{itemize}
\item {\url{https://docs.pytest.org/en/latest/xunit_setup.html}}
\item {\url{https://en.wikipedia.org/wiki/Code_coverage}}
\item{\url{https://docs.pytest.org/en/latest/xunit_setup.html}}
\item{\url{https://en.wikipedia.org/wiki/Code_coverage}}
\item{\url{http://pytest.readthedocs.io/en/reorganize-docs/new-docs/user/pytest_raises.html}}
\end{itemize}
\end{frame}
......
Tutorials/T05-PyUnit/slides/exception-not-raised.png

58.1 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