We discuss the backtesting of investment and trading strategies. We start with the challenges and pitfalls: overfitting, data preparation, and the effects of randomness. Then, we introduce and describe R software for backtesting. We demonstrate how to use the software for univariate and multivariate strategies (i.e. portfolio strategies) for two equity data sets. Specifically, we discuss the implementation and testing of momentum and portfolio optimization models. Throughout, we stress the analysis of sensitivity and robustness checks. Since such analyses require to run many backtests, we also discuss how backtests can be run in parallel