Smart BDD Testing Using Cucumber and Jacoco

Total Page:16

File Type:pdf, Size:1020Kb

Smart BDD Testing Using Cucumber and Jacoco www.hcltech.com Smart BDD Testing Using Cucumber and JaCoCo Business assurance $ Testing AuthOr: Arish Arbab is a Software Engineer at HCL Singapore Pte Limited, having expertize on Agile GUI/API Automation methodologies. WHITEPAPER ApriL 2015 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 TABLE OF CONTENTS INTRODUCTION 3 PROBLEM FACED 3 SOLUTION APPROACH 4 BENEFITS 6 IMPROVEMENTS 7 APPLICABILITY TO OTHER PROJECTS 7 UPCOMING FEATURES 7 REFERENCES 8 APPRECIATIONS RECEIVED 8 ABOUT HCL 9 © 2015, HCL TECHNOLOGIES. REPRODUCTION PROHIBITED. THIS DOCUMENT IS PROTECTED UNDER COPYRIGHT BY THE AUTHOR, ALL RIGHTS RESERVED. 2 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 INTRODUCTION Behavioral Driven Development (BDD) testing uses natural language to describe the “desired behavior” of the system that can be understood by the developer, tester and the customer. It is a synthesis and refinement of practices stemming from TDD and ATDD. It describes behaviors in a single notation that is directly accessible to domain experts, testers and developers for improving communication. It focuses on implementing only those behaviors, which contribute most directly to the business outcomes for optimizing the scenarios. PROBLEM FACED By using the traditional automation approach, and if given a summary report of automated tests to the business analysts, then it is guaranteed that the report would be met with a blank expression. This makes it tricky to prove that the tests are correct— do they match the requirement and, if this changes, what tests need to change to reflect this? The whole idea behind BDD is to write tests in plain English, describing the behaviors of the thing that you are testing. The main advantage of this is that the tests reflect the user stories and the business requirements of the application. Therefore, the results generated can be read by a non-technical person, e.g., a project sponsor, a domain expert, a business analyst, and the tests can be validated against the requirements for better operational efficiency. To achieve the BDD approach, there is an open source tool—Cucumber—that parses the scenarios/tests that are written in Gherkin language (GWT). This tool also interacts with the API/Junit/Source code of an application, using its step definitions test code. The best option to get the business intent into our tests is to have clear deliverables and acceptance criteria in the user stories. These can be then translated into feature tests containing scenarios written in Gherkin Language. BDD is the “outside-in” software development methodology, which has changed the tester’s role dramatically in the recent years and bridges the communication gap between business and technology. This innovative approach has the potential to shape a new organization standard with new SDET roles. Problems faced while implementing the new framework: y Justifying the coverage done by this framework becomes difficult as the complexity of the application code increases y Exposing APIs/Source Code was difficult as developers disagreed y Converting the software requirement into GWT format at the later stages of the software development utilized more efforts y Requiring testers with good technical/coding knowledge y Extending the Junit by using the mocking techniques or spring-based test was a hindrance when the complexity of the code increased y Convincing the BTMs to review the scenarios on every day was difficult © 2015, HCL TECHNOLOGIES. REPRODUCTION PROHIBITED. THIS DOCUMENT IS PROTECTED UNDER COPYRIGHT BY THE AUTHOR, ALL RIGHTS RESERVED. 3 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 SOLUTION APPROACH Traditionally, software requirement was written in simple English sentences, but to convert those requirements into GWT format required an extra effort that should be properly handled. As GWT approach results in better quality of product, requirement should be written in GWT format by the business analyst at the early stages of software development rather than writing the requirement in domain-specific language. Set of scenarios should depict a particular user story. Implementing this approach in a later stage may increase the cost of a project. Example of writing the scenarios in the abovementioned format would be: Traditional software requirement: As a user, I want to login to the application with valid credentials. Simple Cucumber Feature File in Gherkin Format: Feature: Login to the system, User should be allowed to login with valid credentials Scenario: Login Success Given The login page is opened When I input valid username and password in the textboxes And I click the login button Then I logged in successfully. Step definitions for matching scenarios: Similarly for “When” and “Then,” step definitions are created. Corresponding step definitions are then written, and the result is displayed in the above format that assures developer/tester/BA and customers that a particular software requirement has been successfully implemented. Common method of testing an application at the API level requires its API or web services. However, if the application has neither the API available nor the developers who want to create it for testing purposes, then the problem arises to test the code written by developer without any extra development effort. To overcome this problem, Junit classes that are written by developers can be used to call the respective service methods. However, if the unit testing is being done using mocking technique, then it would be difficult to test the actual functionality of the application. So, in order to use the Junit methods effectively, dependency injections techniques can be used at the testing end. Such usage would call the Junit method by passing a particular dependency, which, in turn, calls the real service method. © 2015, HCL TECHNOLOGIES. REPRODUCTION PROHIBITED. THIS DOCUMENT IS PROTECTED UNDER COPYRIGHT BY THE AUTHOR, ALL RIGHTS RESERVED. 4 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 BDD approach—detailed explanation of using Cucumber by leveraging Junit The pictorial representation of Cucumber automation framework: App Service Methods Model Service Methods Junit Classes Junit Classes containing unit test methods Cucumber Step Definitions Cucumber Cucumber Main(Driver) Feature File(Scenarios) DB, Test Data Test Result And Reports Data(.xlsx) Database HTML Reports, Screen shots, logs of failed scenarios etc. Flow of the BDD framework using Cucumber is as follows- y The test data, which is to be used in the scenarios, is stored in Excel sheet or MySql Database. y The test data is then passed to feature file, containing scenarios written in GWT format. Scenarios are denoted by certain tags. y Driver class decides which scenario among the entire features files should be executed by proving a proper tag value. Before running a particular feature, dependency used in application is injected to avoid mocking unit testing framework. y Appropriate matching method defined in the Cucumber step definition file is called. y From the step definition, appropriate unit test method of the parameterized Junit class is called and, thus, test data is passed into it. y Unit test method, which, in turn, calls the real service method by passing the test data to it. y Response is then returned from the service method to unit test method, which, in turn, passes the information to Cucumber step definition file. y Expected response is validated against the returned (actual) response in the step definition. y Logs are created upon failure or success and an auto HTML report is created, depicting the passed and failed scenarios in appropriate colors. © 2015, HCL TECHNOLOGIES. REPRODUCTION PROHIBITED. THIS DOCUMENT IS PROTECTED UNDER COPYRIGHT BY THE AUTHOR, ALL RIGHTS RESERVED. 5 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 Now, if we have the API available, then, instead of calling the Junit test method, the API method is called directly and rest of the flow remains the same. Then the question arises, “Whether or not we are covering all the areas of an application with our test as the scenarios written are very behavioral specific?” Here the need for the code coverage arises. JaCoCo is one of the tools, which can be integrated with Cucumber Test, and the code coverage report generated can be easily read by customers/developers/business analysts and testers. The traditional way of testing may work out with testers, having less technical knowledge. Nevertheless, as we can clearly point out by seeing the above solutions and exposure of code to tester. The need for a tester with good coding skills is prerequisite to implement this approach successfully. JaCoCo report Cucumber test execution can be integrated into CI (Jenkins) server and can be executed depending upon the need. Now, when we have everything in place— scenarios, test code and test results—it becomes difficult to convince the BTMs to review the scenarios on a daily basis. There is another open-source tool available that overcomes these difficulties: Pickles, open-source living document generator. This tool generates the document consisting of the scenarios, which can be easily reviewed by the customer as it supports advance search capabilities. BENEFITS Key Benefits y Cucumber and JaCoCo are open-source tools, which provide equal benefits that other paid tools provide. y Around 80% reduction in the test execution time as compared to manual testing. y Cucumber can be integrated with existing tools like Selenium, TestComplete and Q T P. y Quality of an application increased as the defect is found at an early stage of development. y Cucumber can be used to test REST and SOAP Web services, thereby, easily adjusting in traditional way of API automation. © 2015, HCL TECHNOLOGIES. REPRODUCTION PROHIBITED. THIS DOCUMENT IS PROTECTED UNDER COPYRIGHT BY THE AUTHOR, ALL RIGHTS RESERVED. 6 SMART BDD TESTING USING CUCUMBER AND JACOCO | APRIL 2015 y Unlike other API testing tools, it produces more detailed, easy-to-understand test execution report for client, developer, BA and tester regardless of their technical knowledge.
Recommended publications
  • Taming Functional Web Testing with Spock and Geb
    Taming Functional Web Testing with Spock and Geb Peter Niederwieser, Gradleware Creator, Spock Contributor, Geb The Actors Spock, Geb, Page Objects Spock “Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, RSpec, jMock, Mockito, Groovy, Scala, Vulcans, and other fascinating life forms. Spock (ctd.) http://spockframework.org ASL2 licence Serving mankind since 2008 Latest releases: 0.7, 1.0-SNAPSHOT Java + Groovy JUnit compatible Loves Geb Geb “Geb is a browser automation solution. It brings together the power of WebDriver, the elegance of jQuery content selection, the robustness of Page Object modelling and the expressiveness of the Groovy language. It can be used for scripting, scraping and general automation — or equally as a functional/web/acceptance testing solution via integration with testing frameworks such as Spock, JUnit & TestNG. Geb (ctd.) http://gebish.org ASL2 license Serving mankind since 2009 Latest releases: 0.7.2, 1.0-SNAPSHOT Java + Groovy Use with any test framework Loves Spock First-class page objects Page Objects “The Page Object pattern represents the screens of your web app as a series of objects. Within your web app's UI, there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place.
    [Show full text]
  • Pragmatic Unit Testingin Java 8 with Junit
    www.it-ebooks.info www.it-ebooks.info Early praise for Pragmatic Unit Testing in Java 8 with JUnit Langr, Hunt, and Thomas demonstrate, with abundant detailed examples, how unit testing with JUnit works in the real world. Beyond just showing simple iso- lated examples, they address the hard issues–things like mock objects, databases, multithreading, and getting started with automated unit testing. Buy this book and keep it on your desk, as you’ll want to refer to it often. ➤ Mike Cohn Author of Succeeding with Agile, Agile Estimating and Planning, and User Stories Applied Working from a realistic application, Jeff gives us the reasons behind unit testing, the basics of using JUnit, and how to organize your tests. This is a super upgrade to an already good book. If you have the original, you’ll find valuable new ideas in this one. And if you don’t have the original, what’s holding you back? ➤ Ron Jeffries www.ronjeffries.com Rational, balanced, and devoid of any of the typical religious wars surrounding unit testing. Top-drawer stuff from Jeff Langr. ➤ Sam Rose This book is an excellent resource for those new to the unit testing game. Experi- enced developers should also at the very least get familiar with the very helpful acronyms. ➤ Colin Yates Principal Architect, QFI Consulting, LLP www.it-ebooks.info We've left this page blank to make the page numbers the same in the electronic and paper books. We tried just leaving it out, but then people wrote us to ask about the missing pages.
    [Show full text]
  • Comparative Analysis of Junit and Testng Framework
    International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 05 Issue: 05 | May-2018 www.irjet.net p-ISSN: 2395-0072 Comparative Analysis of JUnit and TestNG framework Manasi Patil1, Mona Deshmukh2 Student, Dept. of MCA, VES Institute of Technology, Maharashtra, India1 Professor, Dept. of MCA, VES Institute of Technology, Maharashtra, India2 ---------------------------------------------------------------------***--------------------------------------------------------------------- Abstract - Testing is an important phase in SDLC, Testing It is flexible than Junit and supports parametrization, parallel can be manual or automated. Nowadays Automation testing is execution and data driven testing. widely used to find defects and to ensure the correctness and The Table – 1 compares different functionalities of TestNG completeness of the software. Open source framework can be and JUnit framework. used for automation testing such as Robotframework, Junit, Spock, NUnit, TestNG, Jasmin, Mocha etc. This paper compares Table -1: Functionality TestNG vs JUnit JUnit and TestNG based on their features and functionalities. Key Words: JUnit, TestNG, Automation Framework, Functionality TestNG JUnit Automation Testing, Selenium TestNG, Selenium JUnit Yes 1. INTRODUCTION Support Annotations Yes Yes Support Test Suit Initialization Yes Testing a software manually is tedious work, and takes lot of No time and efforts. Automation saves lot of time and money, Support for Tests groups Yes also it increases the test coverage
    [Show full text]
  • Mastering Software Testing with Junit 5: Comprehensive Guide to Develop
    Mastering Software Testing with JUnit 5 Comprehensive guide to develop high quality Java applications Boni García BIRMINGHAM - MUMBAI Mastering Software Testing with JUnit 5 Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: October 2017 Production reference: 1231017 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78728-573-6 www.packtpub.com Credits Author Copy Editor Boni García Charlotte Carneiro Reviewers Project Coordinator Luis Fernández Muñoz Ritika Manoj Ashok Kumar S Commissioning Editor Proofreader Smeet Thakkar Safis Editing Acquisition Editor Indexer Nigel Fernandes Aishwarya Gangawane Content Development Editor Graphics Mohammed Yusuf Imaratwale Jason Monteiro Technical Editor Production Coordinator Ralph Rosario Shraddha Falebhai About the Author Boni García has a PhD degree on information and communications technology from Technical University of Madrid (UPM) in Spain since 2011.
    [Show full text]
  • Spock Vs Junit 5 - Clash of the Titans
    Spock vs JUnit 5 - Clash of the Titans Marcin Zajączkowski Stockholm, 6 February 2019 @SolidSoftBlog About me Areas of expertise Automatic Testing / TDD Software Craftsmanship / Code Quality Deployment Automation / Continuous Delivery Concurrency / Parallel Computing / Reactive Systems . FOSS projects author and contributor blogger trainer Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Comprehensive Kubernetes & Openshift services with Continuous Delivery with Jenkins https://mindboxgroup.com/ [email protected] Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Presentation goal Help you decide what is the best testing framework for Java code Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Presentation plan historical outline selected JUnit 5 & Spock features comparison summary Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Version statement This comparison is valid for JUnit 5.4.0-RC2 and Spock 1.3-RC1 Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Historical outline Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Unit testing in Java - historical outline JUnit - first xUnit for Java - 2000 Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Unit testing in Java - historical outline JUnit - first xUnit for Java - 2000 TestNG - Java 5 leveraged in tests - 2004 with some unique (at the time) features Marcin Zajączkowski @SolidSoftBlog https://blog.solidsoft.info/ Unit
    [Show full text]
  • Java Junit for Regression Testing
    Java JUnit for Unit Testing JUNIT API (JUNIT 4.X) ERIC Y. CHOU, PH.D. IEEE SENIOR MEMBER What is JUnit JUnit is a 3rd-Party API from junit.org JUnit Developer(s) Kent Beck, Erich Gamma, David Saff, Mike Clark (University of Calgary) Stable release 4.12 / December 4, 2014 Written in Java Operating system Cross-platform Type Unit testing tool License Eclipse Public License Website junit.org Compatible with Other Languages Ports Actionscript (FlexUnit) Haskell (HUnit) Ada (AUnit) JavaScript (JSUnit) C (CUnit) Microsoft .NET (NUnit) C# (NUnit) Objective-C (OCUnit) C++ (CPPUnit, CxxTest) OCaml (OUnit) Coldfusion (MXUnit) Perl (Test::Class and Test::Unit) Erlang (EUnit) PHP (PHPUnit) Eiffel (Auto-Test) Python (PyUnit) Fortran (fUnit, pFUnit) Qt (QTestLib) Delphi (DUnit) R (RUnit) Free Pascal (FPCUnit) Ruby (Test::Unit) Automating Tests Nearly every programmer tests his code. Testing with JUnit isn't a totally different activity from what you're doing right now. It's a different way of doing what you're already doing. The difference is between testing, that is checking that your program behaves as expected, and having a battery of tests, little programs that automatically check to ensure that your program behaves as expected. In this chapter we'll go from typical println( )-based testing code to a fully automated test. JUnit's Goals Every framework has to resolve a set of constraints, some of which seem always to conflict with each other. JUnit is no exception; simultaneously tests should be: •Easy to write. Test code should contain no extraneous overhead. •Easy to learn to write.
    [Show full text]
  • HCI OSS Licenses V1.6.4.Pdf
    HITACHI Inspire the Next 2535 Augustine Drive Santa Clara, CA 95054 USA Contact Information : Hitachi Content Intelligence Product Manager Lumada Data Catalog v 1 . 6 . 4 Hitachi Vantara LLC 2535 Augustine Dr. Santa Clara CA 95054 Component Version License Modified "Java Concurrency in Practice" book 1 Creative Commons Attribution 2.5 annotations #NAME? 0.1.38-webpack MIT License #NAME? 2.3.0 Apache License 2.0 #NAME? 3.3.0 MIT License abbrev 1.0.9 ISC License BSD 3-clause "New" or "Revised" ace-builds 1.2.8 License BSD 3-clause "New" or "Revised" ace-builds 1.3.3 License Acorn 1.2.2 MIT License Acorn 2.7.0 MIT License Acorn 4.0.13 MIT License Aether :: API 1.0.2.v20150114 Eclipse Public License 1.0 Aether :: SPI 1.0.2.v20150114 Eclipse Public License 1.0 Aether :: Utilities 1.0.2.v20150114 Eclipse Public License 1.0 Aether Connector Basic 1.0.2.v20150114 Eclipse Public License 1.0 Aether Implementation 1.0.2.v20150114 Eclipse Public License 1.0 Aether Transport Wagon 1.0.2.v20150114 Eclipse Public License 1.0 agentkeepalive 2.2.0 MIT License aggs-matrix-stats 5.3.1 Apache License 2.0 airbnb/chronos 2.3.3 Apache License 2.0 aircompressor 0.8 Apache License 2.0 Airline - io.airlift:airline 0.6 Apache License 2.0 akka-actor 2.3.16 Apache License 2.0 akka-persistence_2.11 2.5.5 Apache License 2.0 alibaba/x-deeplearning 20181224-snapshot-ffc8b733 Apache License 2.0 An open source Java toolkit for 0.9.0 Apache License 2.0 Amazon S3 An open source Java toolkit for 0.9.4 Apache License 2.0 Amazon S3 HITACHI Inspire the Next 2535 Augustine Drive
    [Show full text]
  • Java Testing with Spock by Konstantinos Kapelonis
    SAMPLE CHAPTER Konstantinos Kapelonis FOREWORD BY Luke Daley MANNING Java Testing with Spock by Konstantinos Kapelonis Sample Chapter 1 Copyright 2016 Manning Publications brief contents PART 1FOUNDATIONS AND BRIEF TOUR OF SPOCK ................... 1 1 ■ Introducing the Spock testing framework 3 2 ■ Groovy knowledge for Spock testing 31 3 ■ A tour of Spock functionality 62 PART 2STRUCTURING SPOCK TESTS ...................................... 89 4 ■ Writing unit tests with Spock 91 5 ■ Parameterized tests 127 6 ■ Mocking and stubbing 157 PART 3SPOCK IN THE ENTERPRISE ...................................... 191 7 ■ Integration and functional testing with Spock 193 8 ■ Spock features for enterprise testing 224 Part 1 Foundations and brief tour of Spock Spock is a test framework that uses the Groovy programming language. The first part of the book expands on this by making sure that we (you, the reader, and me, the author) are on the same page. To make sure that we are on the same page in the most gradual way, I first define a testing framework (and why it’s needed) and introduce a subset of the Groovy syntax needed for writing Spock unit tests. I know that you’re eager to see Spock tests (and write your own), but some features of Spock will impress you only if you’ve first learned a bit about the goals of a test framework and the shortcomings of current test frameworks (for example, JUnit). Don’t think, however, that this part of the book is theory only. Even at this early stage, this brief tour of Spock highlights includes full code listings and some out-of-the-ordinary examples.
    [Show full text]
  • Sebastian Bergmann Phpunit Manual Sebastian Bergmann
    PHPUnit Manual Sebastian Bergmann PHPUnit Manual Sebastian Bergmann Publication date Edition for PHPUnit 6.5. Updated on 2017-12-07. Copyright © 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Sebastian Bergmann This work is licensed under the Creative Commons Attribution 3.0 Unported License. Table of Contents 1. Installing PHPUnit ..................................................................................................... 1 Requirements ........................................................................................................ 1 PHP Archive (PHAR) ............................................................................................ 1 Windows ..................................................................................................... 1 Verifying PHPUnit PHAR Releases ................................................................. 2 Composer ............................................................................................................. 4 Optional packages ................................................................................................. 4 2. Writing Tests for PHPUnit .......................................................................................... 5 Test Dependencies ................................................................................................. 5 Data Providers ...................................................................................................... 8 Testing Exceptions ..............................................................................................
    [Show full text]
  • Junit 5 User Guide
    JUnit 5 User Guide Stefan Bechtold, Sam Brannen, Johannes Link, Matthias Merdes, Marc Philipp, Christian Stein Version 5.1.1 Table of Contents 1. Overview . 1 1.1. What is JUnit 5? . 1 1.2. Supported Java Versions . 1 1.3. Getting Help . 1 2. Installation . 1 2.1. Dependency Metadata . 1 2.2. Dependency Diagram . 3 2.3. JUnit Jupiter Sample Projects. 4 3. Writing Tests . 4 3.1. Annotations . 4 3.2. Standard Test Class. 6 3.3. Display Names . 8 3.4. Assertions . 8 3.5. Assumptions. 13 3.6. Disabling Tests. 14 3.7. Conditional Test Execution. 15 3.8. Tagging and Filtering. 20 3.9. Test Instance Lifecycle . 21 3.10. Nested Tests . 22 3.11. Dependency Injection for Constructors and Methods. 24 3.12. Test Interfaces and Default Methods . 27 3.13. Repeated Tests. 32 3.14. Parameterized Tests . 35 3.15. Test Templates . 45 3.16. Dynamic Tests . 45 4. Running Tests . 49 4.1. IDE Support . 49 4.2. Build Support. 50 4.3. Console Launcher. 61 4.4. Using JUnit 4 to run the JUnit Platform . 65 4.5. Configuration Parameters . 67 4.6. Tag Expressions . 67 5. Extension Model . 68 5.1. Overview . 68 5.2. Registering Extensions . 68 5.3. Conditional Test Execution. 72 5.4. Test Instance Post-processing . 73 5.5. Parameter Resolution . 73 5.6. Test Lifecycle Callbacks. 73 5.7. Exception Handling . 76 5.8. Providing Invocation Contexts for Test Templates . 77 5.9. Keeping State in Extensions . 79 5.10. Supported Utilities in Extensions .
    [Show full text]
  • Comparing Spock and Junit by Konstantinos Kapelonis, Java Testing with Spock
    Comparing Spock and Junit By Konstantinos Kapelonis, Java Testing with Spock Spock is also a superset of the defacto testing framework for Java: Junit. In this article, excerpted from Java Testing with Spock, we will compare Spock with Junit. In the Java world, there has been so far only one solution for unit tests. The venerable JUnit framework is the obvious choice and has become almost synonymous with unit testing. JUnit has the largest mind share among developers who are entrenched in their traditions and don't want to look any further. Even TestNG which has several improvements and is also fully compatible with JUnit has failed to gain significant traction. But fear not! A new testing solution is now available in the form of Spock. Spock is a testing framework written in Groovy but able to test both Java and Groovy code. It is fully compatible with JUnit (it actually builds on top of the JUnit runner) and provides a cohesive testing package that also includes mocking/stubbing capabilities It is hard to compare JUnit and Spock in a single article, because both tools have a different philosophy when it comes to testing. JUnit is a Spartan library that provides the absolutely necessary thing you need to test and leaves additional functionality (such as mocking and stubbing) to external libraries. Spock has a holistic approach, providing you a superset of the capabilities of JUnit, while at the same time reusing its mature integration with tools and developments environments. Spock can do everything that JUnit does and more, keeping backwards compatibility as far as test runners are concerned.
    [Show full text]
  • The Junit Unit Testing Framework Sunit Xunit (1) Xunit
    xUnit (1) The JUnit Unit Testing Framework xUnit is a family of unit testing frameworks that follow the architecture of the SUnit unit testing framework for the SmallTalk programming language. Péter Jeszenszky JUnit was the first member of the xUnit family that became widely used and popular. Over the years JUnit have been ported to many other programming 2021.05.09. languages. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 1 / 25 Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 3 / 25 SUnit xUnit (3) Other notable members of the xUnit family: C++: SUnit is a unit testing framework for the SmallTalk programming language that is considered to be the mother of all unit testing frameworks. CppUnit (license: GNU LGPLv2.1) https://www.freedesktop.org/wiki/Software/cppunit/ It was written by Kent Beck in 1994. .NET: Website: http://sunit.sourceforge.net/ NUnit (license: MIT License) https://nunit.org/ See: Martin Fowler. xUnit. 17 January 2006. https://github.com/nunit/nunit https://martinfowler.com/bliki/Xunit.html Python: unittest (license: Python Software Foundation License) https://docs.python.org/3/library/unittest.html Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 2 / 25 Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 4 / 25 JUnit History Architecture (1) JUnit was written by Kent Beck and Erich Gamma in 1997. JUnit 5 has a modular structure: The current major version is 5. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 5 / 25 Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09.
    [Show full text]