

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Tests}
\subtitle{Why Testing is Important}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Goal}

\begin{itemize}
\item why tests are important?
\item what are their advantages?
\item what are the techniques to write good tests?
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Pros}

\begin{itemize}
\item Finding problems
\item Understanding code
\item Increase trust
\end{itemize}

\begin{itemize}
\item Collateral pros
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Finding Problems: Pros}

\begin{itemize}
\item find bugs when they appear
\item improve customer trust
\item reproduce complex scenari
\item check contracts of super types
\item guarantee old bugs won't come back
\item isolate the problem
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Finding Problems: Characteristics of a Good Test Suite}

\begin{itemize}
\item check extreme cases (e.g., null, 0 and empty)
\item check complex cases (e.g., exceptions, network pbs)
\item 1 test for each bug (at least)
\item good coverage
\item check abstractions
\item check units independently
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code}

\begin{listing}{}
convert
   | s |
   s := '#000000' copy.
   s at: 2 put: (Character digitValue: ((rgb bitShift: -6 - RedShift) bitAnd: 15)).
   s at: 3 put: (Character digitValue: ((rgb bitShift: -2 - RedShift) bitAnd: 15)).
   s at: 4 put: (Character digitValue: ((rgb bitShift: -6 - GreenShift) bitAnd: 15)).
   s at: 5 put: (Character digitValue: ((rgb bitShift: -2 - GreenShift) bitAnd: 15)).
   s at: 6 put: (Character digitValue: ((rgb bitShift: -6 - BlueShift) bitAnd: 15)).
   s at: 7 put: (Character digitValue: ((rgb bitShift: -2 - BlueShift) bitAnd: 15)).
   ^ s
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code}

\begin{listing}{}
testConvert
   self assert: Color white convert = '#FFFFFF'.
   self assert: Color red convert = '#FF0000'.
   self assert: Color black convert = '#000000'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code}

\begin{listing}{}
testConvert2
   | table aColorString |
   table := #('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'A' 'B' 'C' 'D' 'E' 'F').

   table do: [ :each |
      aColorString := '#', each, each, '0000'.
      self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].

   table do: [ :each |
      aColorString := '#', '00', each, each, '00'.
      self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].

   table do: [ :each |
      aColorString := '#', '0000', each, each.
      self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code}

\begin{listing}{}
testBitShift
   self assert: (2r11 bitShift: 2) equals: 2r1100.
   self assert: (2r1011 bitShift: -2) equals: 2r10.

testShiftOneLeftThenRight
   "Shift 1 bit left then right and test for 1"
   1 to: 100 do: [:i | self assert: ((1 bitShift: i) bitShift: i negated) = 1].
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code: Pros}

\begin{itemize}
\item give simple and reproducible examples
\item explain an API
\item give up-to-date documentation
\item check conformity of new code
\item offer a first client to new code
\item force a modular design
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Understanding Code: Characteristics of a Good Test Suite}

\begin{itemize}
\item deterministic
\item automatic
\item self-explained
\item simple
\item unit
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Increasing Trust: Pros}

\begin{itemize}
\item accelerate bug detection
\item accelerate new code checking
\item ease refactorings
\item prevent regressions
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Increasing Trust: Characteristics of a Good Test Suite}

\begin{itemize}
\item change less frequently than the rest
\item good code coverage
\item deterministic
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Collateral Pros}

\begin{itemize}
\item improve feeling of customers who care
\item allow for automatic bug fixing
\item improve type inference
\item provide examples to variable values
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Testing Abstractions}

How do you test contracts of abstract types?
\end{frame}



\begin{frame}[fragile]

\frametitle{Testing Abstractions}

How do you test that one and only one state is active at any time?


\begin{center}
\includegraphics[width=0.5\textwidth]{figures/tests-actions.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Testing Abstractions}


\begin{center}
\includegraphics[width=0.7\textwidth]{figures/tests-actions-abstract-classes.png}\end{center}


\begin{listing}{}
testOnlyOneValidStateAtEachMoment
   | action |
   action := self createAction.
   self assert: action isReady.
   self deny: action isInProgress. self deny: action isFinished.

   [ action isFinished ] whileFalse: [
      action doStep.
      self deny: action isReady.
      self assert: action isFinished = action isInProgress not ].

   self deny: action isReady. self deny: action isInProgress.
   self assert: action isFinished
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Testing Abstractions}

\begin{itemize}
\item parallel hierarchies
\item test must be in the highest abstraction
\item factory method
\end{itemize}


\begin{center}
\includegraphics[width=0.8\textwidth]{figures/tests-actions-parallel-hierarchies.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Mocking}

How do you test that a questionnaire only accepts compatible answers from the user?


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/tests-questionnaire-model.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Mocking}

How do you test that a questionnaire only accepts compatible answers from the user?


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/tests-questionnaire-mocks.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Mocking}


\begin{center}
\includegraphics[width=0.6\textwidth]{figures/tests-questionnaire-mocks.png}\end{center}


\begin{listing}{}
readAnswerAsLongAsItIsNotCompatible
   | nbRejectsBeforeAccept question ui |
   nbRejectsBeforeAccept := 3.
   question := MockQuestion new nbRejects: nbRejectsBeforeAccept.
   ui := MockQuestionnaireUI new.
   self assert: ui nbReadAnswers equals: 0.
   self assert: question nbAcceptAnswerCalls equals: 0.
   questionnaire runQuestion: question on: ui.
   self assert: ui nbReadAnswers equals: nbRejectsBeforeAccept + 1.
   self assert: question nbAcceptAnswerCalls equals: nbRejectsBeforeAccept + 1.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Mocking}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/tests-questionnaire-mocks.png}\end{center}


\begin{itemize}
\item mocks are reusable across tests
\item mocks can be generated with mocking frameworks
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Different Testing Levels}


\begin{center}
\includegraphics[width=0.6\textwidth]{figures/tests-pyramid.png}\end{center}


\url{http://martinfowler.com/bliki/TestPyramid.html}

\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
