Abstract
Property-based testing tools test software against a specification, rather than a set of examples. This tutorial paper presents five generic approaches to writing such specifications (for purely functional code). We discuss the costs, benefits, and bug-finding power of each approach, with reference to a simple example with eight buggy variants. The lessons learned should help the reader to develop effective property-based tests in the future.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
Recall that we have not imposed any balance condition on our trees. If we were to repeat this entire exercise for balanced trees, then we would need a stronger invariant to capture the balance condition, but we would still face the same problem in this property, since balance conditions don’t require a unique tree shape. Both trees in this example are balanced—they are just different balanced representations of the same information.
- 8.
- 9.
- 10.
- 11.
A company founded in 2006 by the author and Thomas Arts, to commercialize property based testing. See http://quviq.com.
References
Amaral, C., Florido, M., Santos Costa, V.: PrologCheck – property-based testing in prolog. In: Codish, M., Sumii, E. (eds.) FLOPS 2014. LNCS, vol. 8475, pp. 1–17. Springer, Cham (2014). https://doi.org/10.1007/978-3-319-07151-0_1
Arts, T., Hughes, J., Johansson, J., Wiger, U.T.: Testing telecoms software with Quviq QuickCheck. In: Feeley, M., Trinder, P.W. (eds.) Proceedings of the 2006 ACM SIGPLAN Workshop on Erlang, Portland, Oregon, USA, 16 September 2006, pp. 2–10. ACM (2006)
Barr, E.T., Harman, M., McMinn, P., Shahbaz, M., Yoo, S.: The oracle problem in software testing: a survey. IEEE Trans. Soft. Eng. 41(5), 507–525 (2015)
Braquehais, R.M.: Tools for discovery, refinement and generalization of functional properties by enumerative testing. Ph.D. thesis, University of York, UK (2017)
Broy, M., Jonsson, B., Katoen, J.-P., Leucker, M., Pretschner, A. (eds.): Model-Based Testing of Reactive Systems. LNCS, vol. 3472. Springer, Heidelberg (2005). https://doi.org/10.1007/b137241
Chen, T.Y., Cheung, S.C., Yiu, S.M.: Metamorphic testing: a new approach for generating next test cases. Technical report, HKUST-CS98-01, Department of Computer Science, Hong Kong (1998)
Chen, T.Y., et al.: Metamorphic testing: a review of challenges and opportunities. ACM Comput. Surv. 51(1), 4:1–4:27 (2018)
Claessen, K.: Inductive testing. Private communication. https://docs.google.com/presentation/d/1pejW9foV4ZAw5e03kYR3urNQsIPobomY_5HshxZQpLc/edit?usp=drivesdk
Claessen, K., Hughes, J.: QuickCheck: a lightweight tool for random testing of Haskell programs. In: Proceedings of 5th ACM SIGPLAN International Conference on Functional Programming, ICFP 2000 (2000)
Lindley, S., McBride, C., Trinder, P., Sannella, D. (eds.): A List of Successes That Can Change the World. LNCS, vol. 9600. Springer, Cham (2016). https://doi.org/10.1007/978-3-319-30936-1
Floyd, R.W.: Assigning meanings to programs. In: Colburn, T.R., Fetzer, J.H., Rankin, T.L. (eds.) Program Verification, vol. 14, pp. 65–81. Springer, Dordrecht (1993). https://doi.org/10.1007/978-94-011-1793-7_4
Godefroid, P., Klarlund, N., Sen, K.: DART: directed automated random testing. ACM SIGPLAN Not. 40, 213–223 (2005)
Guttag, J.V., Horning, J.J.: The algebraic specification of abstract data types. Acta Inform. 10(1), 27–52 (1978)
Hoare, C.A.: Proof of correctness of data representations. Acta Inform. 1(4), 271–281 (1972)
Hoare, C.A.R.: An axiomatic basis for computer programming. Commun. ACM 12(10), 576–580 (1969)
Hughes, J.: Experiences with QuickCheck: testing the hard stuff and staying sane. In: Lindley et al. [10], pp. 169–186 (2016)
Löscher, A., Sagonas, K.: Targeted property-based testing. In: Proceedings of the 26th ACM SIGSOFT International Symposium on Software Testing and Analysis, pp. 46–56. ACM (2017)
Meyer, B.: Applying ‘design by contract’. Computer 25(10), 40–51 (1992)
Nilsson, R.: ScalaCheck: The Definitive Guide. Artima Press, Mountain View (2014)
Papadakis, M., Sagonas, K.: A proper integration of types and function specifications with property-based testing. In: Proceedings of the 10th ACM SIGPLAN Workshop on Erlang, pp. 39–50. ACM (2011)
Pike, L.: SmartCheck: automatic and efficient counterexample reduction and generalization. In: Swierstra, W. (ed.) Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Gothenburg, Sweden, 4–5 September 2014, pp. 53–64. ACM (2014)
Polya, G.: How To Solve It! A System of Thinking Which Can Help You Solve Any Problem. Princeton University Press, Princeton (1945)
Runciman, C., Naylor, M., Lindblad, F.: SmallCheck and lazy SmallCheck: automatic exhaustive testing for small values. In: Gill, A. (ed.) Proceedings of the 1st ACM SIGPLAN Symposium on Haskell, Haskell 2008, Victoria, BC, Canada, 25 September 2008, pp. 37–48. ACM (2008)
Sen, K., Marinov, D., Agha, G.: CUTE: a concolic unit testing engine for C. ACM SIGSOFT Softw. Eng. Notes 30, 263–272 (2005)
Spivey, J.M.: Understanding Z: A Specification Language and Its Formal Semantics, vol. 3. Cambridge University Press, Cambridge (1988)
Acknowledgements
I’m grateful to the anonymous referees for many useful suggested improvements, and to Vetenskapsrådet for funding this work under the SyTeC grant.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Metamorphic Properties
A Metamorphic Properties
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this paper
Cite this paper
Hughes, J. (2020). How to Specify It!. In: Bowman, W., Garcia, R. (eds) Trends in Functional Programming. TFP 2019. Lecture Notes in Computer Science(), vol 12053. Springer, Cham. https://doi.org/10.1007/978-3-030-47147-7_4
Download citation
DOI: https://doi.org/10.1007/978-3-030-47147-7_4
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-47146-0
Online ISBN: 978-3-030-47147-7
eBook Packages: Computer ScienceComputer Science (R0)