The Junit Unit Testing Framework

Total Page:16

File Type:pdf, Size:1020Kb

The Junit Unit Testing Framework The JUnit Unit Testing Framework Péter Jeszenszky 2021.05.09. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 1 / 25 SUnit SUnit is a unit testing framework for the SmallTalk programming language that is considered to be the mother of all unit testing frameworks. It was written by Kent Beck in 1994. Website: http://sunit.sourceforge.net/ See: Martin Fowler. xUnit. 17 January 2006. https://martinfowler.com/bliki/Xunit.html Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 2 / 25 xUnit (1) xUnit is a family of unit testing frameworks that follow the architecture of the SUnit unit testing framework for the SmallTalk programming language. 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 languages. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 3 / 25 xUnit (3) Other notable members of the xUnit family: C++: CppUnit (license: GNU LGPLv2.1) https://www.freedesktop.org/wiki/Software/cppunit/ .NET: NUnit (license: MIT License) https://nunit.org/ https://github.com/nunit/nunit 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. 4 / 25 JUnit History JUnit was written by Kent Beck and Erich Gamma in 1997. The current major version is 5. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 5 / 25 JUnit Availability License: Eclipse Public License 2.0 Website: https://junit.org/junit5/ Repository: https://github.com/junit-team/junit5 Maven Central: JUnit artifacts are available in Maven Central The list of JUnit artifacts: https://junit.org/junit5/docs/current/user- guide/#dependency-metadata Documentation: JUnit 5 User Guide https://junit.org/junit5/docs/current/user-guide/ Javadoc: https://junit.org/junit5/docs/current/api/ Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 6 / 25 Architecture (1) JUnit 5 has a modular structure: JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 7 / 25 Architecture (2) JUnit Platform: It serves as a foundation for launching testing frameworks on the JVM. It defines the TestEngine API for developing testing frameworks that runs on the platform. It also provides a ConsoleLauncher to launch the platform from the command line. JUnit Platform is supported by popular IDEs (e.g., IntelliJ IDEA, Eclipse, NetBeans, and Visual Studio Code) and build tools (e.g., Apache Maven and Gradle). JUnit Jupiter: It defines a programming model and an extension model for writing tests and extensions in JUnit 5. It also provides a TestEngine for running Jupiter based tests on the platform. JUnit Vintage: provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 8 / 25 IDE support Apache NetBeans: Writing JUnit Tests in NetBeans IDE http://netbeans.apache.org/kb/docs/java/junit-intro.html Eclipse IDE: IntelliJ IDEA: https://www.jetbrains.com/help/idea/testing.html Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 9 / 25 Apache Maven Support Apache Maven Surefire https://maven.apache.org/surefire/ https://github.com/apache/maven-surefire Maven Surefire Plugin https://maven.apache.org/surefire/maven-surefire-plugin/ Maven Surefire Report Plugin https://maven.apache.org/surefire/maven-surefire-report-plugin/ Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 10 / 25 Test Classes and Methods (1) Test class: any top-level class, static member class, or @Nested class that contains at least one test method. Must not be abstract and must have a single constructor. Test method: any instance method that is annotated with @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, or @TestTemplate. Lifecycle Method: any method that is annotated with @BeforeAll, @AfterAll, @BeforeEach, or @AfterEach. Methods annotated with @BeforeAll and @AfterAll must be static (unless the @TestInstance(Lifecycle.PER_CLASS) annotation is present). Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 11 / 25 Test Classes and Methods (2) Test classes, test methods, and lifecycle methods are not required to be public, but they must not be private. Test methods and lifecycle methods: May be declared locally within the current test class, inherited from superclasses, or inherited from interfaces. Must not be abstract and must not return a value. Both test constructors and methods are permitted to have parameters that enables dependency injection for constructors and methods. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 12 / 25 Test Execution Lifecycle (1) By default, JUnit creates a new instance of each test class before executing each test method that allows individual test methods to be executed in isolation. This “per-method” behavior can be changed, to execute all test methods on the same test instance, annotate a test class with @TestInstance(Lifecycle.PER_CLASS). Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 13 / 25 Test Execution Lifecycle (2) Example: import org.junit.jupiter.api.*; public class LifeCycleTest { LifeCycleTest() { System.out.printf("Constructor creates %s\n", this); } @BeforeAll static void beforeAll() { System.out.println("@BeforeAll static method invoked"); } @AfterAll static void afterAll() { System.out.println("@AfterAll static method invoked"); } @BeforeEach void beforeEach() { System.out.printf("@BeforeEach method invoked on %s\n", this); } @AfterEach void afterEach() { System.out.printf("@AfterEach method invoked on %s\n", this); } @Test void testMethod1() { System.out.printf("testMethod1() method invoked on %s\n", this); } @Test void testMethod2() { System.out.printf("testMethod2() method invoked on %s\n", this); } } Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 14 / 25 Test Execution Lifecycle (3) Example: @BeforeAll static method invoked Constructor creates LifeCycleTest@2145433b @BeforeEach method invoked on LifeCycleTest@2145433b testMethod1() method invoked on LifeCycleTest@2145433b @AfterEach method invoked on LifeCycleTest@2145433b Constructor creates LifeCycleTest@fdefd3f @BeforeEach method invoked on LifeCycleTest@fdefd3f testMethod2() method invoked on LifeCycleTest@fdefd3f @AfterEach method invoked on LifeCycleTest@fdefd3f @AfterAll static method invoked Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 15 / 25 Test Execution Order By default, test methods will be ordered using an algorithm that is deterministic but intentionally nonobvious. This ensures that subsequent runs of a test suite execute test methods in the same order, thereby allowing for repeatable builds. Although true unit tests typically should not rely on the order in which they are executed, there are times when it is necessary to enforce a specific test method execution order. The @TestMethodOrder annotation is provided to control the order in which test methods are executed. Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 16 / 25 Related Libraries and Frameworks (1) Assertion/matcher libraries: AssertJ (license: Apache License 2.0) https://assertj.github.io/doc/ https://github.com/assertj/assertj-core Hamcrest http://hamcrest.org/ Java Hamcrest (license: BSD 3-Clause License) http://hamcrest.org/JavaHamcrest/ https://github.com/hamcrest/JavaHamcrest PyHamcrest (license: BSD 3-Clause License) https://github.com/hamcrest/PyHamcrest ... Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 17 / 25 Related Libraries and Frameworks (2) Mocking frameworks: EasyMock (license: Apache License 2.0) https://easymock.org/ https://github.com/easymock/easymock Mockito (license: MIT License) https://site.mockito.org/ https://github.com/mockito/mockito PowerMock (license: Apache License 2.0) https://github.com/powermock/powermock Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 18 / 25 Related Libraries and Frameworks (3) Databases: DbUnit (license: GNU LGPLv2.1) http://dbunit.sourceforge.net/ Headless browsers: HtmlUnit (license: Apache License 2.0) https://htmlunit.sourceforge.io/ https://github.com/HtmlUnit/htm Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 19 / 25 Capturing System.out with System Lambda (1) The System Lambda library provides support for testing code that uses java.lang.System. License: MIT License Repository: https://github.com/stefanbirkner/system-lambda Availability in Maven Central: com.github.stefanbirkner:system-lambda:1.2.0 Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 20 / 25 Capturing System.out with System Lambda (2) Example: @Test void testMain() throws Exception { String output = tapSystemOut(() -> HelloWorld.main( new String[] {})); assertEquals("Hello, World!\n", output); } Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 21 / 25 Capturing System.out with System Lambda (3) The methods with the suffix Normalized normalize line breaks to \n so that you can run tests with the same assertions on different operating systems. Example: @Test void testMain() throws Exception { String output = tapSystemOutNormalized(() -> HelloWorld.main(new String[] {})); assertEquals("Hello, World!\n", output); } Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 22 / 25 Examples from the Industry: Apache Commons Lang (1) org.apache.commons.lang3.StringUtils: StringUtils.java Javadoc JUnit 5 unit tests: StringUtilsContainsTest.java StringUtilsSubstringTest.java StringUtilsTest.java Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 23 / 25 Examples from the Industry: Apache Commons Lang (2) org.apache.commons.lang3.BitField: BitField.java Javadoc BitFieldTest.java Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 24 / 25 Further Recommended Reading Cătălin Tudose. JUnit in Action. 3rd ed. Manning Publications, 2021. https://github.com/ctudose/junit-in-action-third-edition Boni Garcia. Mastering Software Testing with JUnit 5. Packt Publishing, 2017. https://github.com/PacktPublishing/Mastering- Software-Testing-with-JUnit-5 Péter Jeszenszky The JUnit Unit Testing Framework 2021.05.09. 25 / 25.
Recommended publications
  • Practical Methods for Programmer Testing
    JUnit Recipes Practical Methods for Programmer Testing J.B.Rainsberger with contributions by Scott Stirling MANNING JUnit Recipes Practical Programmer Testing Methods by J.B. Rainsberger Chapter 1 Copyright 2004 Manning Publications Rainsberger.book Page 3 Monday, June 28, 2004 6:42 PM Fundamentals This chapter covers ■ An introduction to Programmer Testing ■ Getting started with JUnit ■ A few good practices for JUnit ■ Why testing replaces debugging 3 Rainsberger.book Page 4 Monday, June 28, 2004 6:42 PM 4 CHAPTER 1 Fundamentals We hate debugging. You look up at the clock to see how late it is because you still have a handful of defects that need to be fixed tonight. Welcome to the “fix” phase of “code and fix,” which is now entering its third month. In that time, you have begun to forget what your home looks like. The four walls of your office—assuming you even have four walls to look at—are more familiar than you ever wanted them to be. You look at the “hot defects” list and see one problem that keeps coming back. You thought you fixed that last week! These testers...when will they leave you alone?! Fire up the debugger, start the application server—grab a coffee because you have five minutes to kill—set a breakpoint or two, enter data in 10 text fields and then press the Go button. As the debugger halts at your first breakpoint, your goal is to figure out which object insists on sending you bad data. As you step through the code, an involuntary muscle spasm—no doubt from lack of sleep—causes you to accidentally step over the line of code that you think causes the problem.
    [Show full text]
  • Bringing Test-Driven Development to Web Service Choreographies
    Journal of Systems and Software • October 2014 • http://www.sciencedirect.com/science/article/pii/S016412121400209X Bringing Test-Driven Development to Web Service Choreographies Felipe Besson,Paulo Moura,Fabio Kon Dejan Milojicic Department of Computer Science Hewlett Packard Laboratories University of São Paulo Palo Alto, USA {besson, pbmoura, kon}@ime.usp.br [email protected] Abstract Choreographies are a distributed approach for composing web services. Compared to orchestrations, which use a centralized scheme for distributed service management, the interaction among the chore- ographed services is collaborative with decentralized coordination. Despite the advantages, choreography development, including the testing activities, has not yet evolved sufficiently to support the complexity of the large distributed systems. This substantially impacts the robustness of the products and overall adoption of choreographies. The goal of the research described in this paper is to support the Test-Driven Development (TDD) of choreographies to facilitate the construction of reliable, decentralized distributed systems. To achieve that, we present Rehearsal, a framework supporting the automated testing of chore- ographies at development-time. In addition, we present a choreography development methodology that guides the developer on applying TDD using Rehearsal. To assess the framework and the methodology, we conducted an exploratory study with developers, whose result was that Rehearsal was considered very helpful for the application of TDD and that the methodology helped the development of robust choreographies. Keywords: Automated testing, Test-Driven Development, Web service choreographies I. Introduction Service-Oriented Architecture (SOA) is a set of principles and methods that uses services as the building blocks for the development of distributed applications.
    [Show full text]
  • Unit Testing Essentials Using Junit 5 and Mockito
    Trivera Technologies IT Training Coaching Courseware Collaborate. Educate. Accelerate! Unit Testing Essentials using JUnit 5 and Mockito (with Best Practices) Explore Unit Testing, JUnit, Best Practices, Testing Apps with Native IDE Support, Debugging, Using Mockito & More w w w . t r i v e r a t e c h . c o m Course Snapshot Course: Unit Testing Essentials using JUnit 5 and Mockito (TT3526) Duration: 3 days Audience & Skill‐Level: This in an introduction to Unit Testing course for experienced Java developers Language / Tools: This course uses JUnit 5 and Mockito. This course is also available for JUnit 4, or JUnit 5 and EasyMock. Hands‐on Learning: This course is approximately 50% hands‐on, combining expert lecture, real‐world demonstrations and group discussions with machine‐based practical labs and exercises. Student machines are required. Delivery Options: This course is available for onsite private classroom presentation, live online virtual presentation, or can be presented in a flexible blended learning format for combined onsite and remote attendees. Please also ask about our Self‐ Paced / Video or QuickSkills / Short Course options. Public Schedule: This course has active dates on our live‐online open enrollment Public Schedule. Customizable: This course agenda, topics and labs can be further adjusted to target your specific training skills objectives, tools and learning goals. Please inquire for details. Overview JUnit 5 and EasyMock make it possible to write higher‐quality Java code. These powerful tools are designed to support robust, predictable and automated testing development in the Java enterprise application arena. Unit Testing Essentials using JUnit 5 and Mockito is a three‐day, hands‐on unit testing course geared for experienced developers who need to get up and running with essential unit testing skills using JUnit, Mockito, and other tools.
    [Show full text]
  • BONUS CHAPTER Contents
    BONUS CHAPTER contents preface xvii acknowledgments xix about this book xxi about the cover illustration xxvii PART 1 A TDD PRIMER ..............................................1 The big picture 3 1 1.1 The challenge: solving the right problem right 5 Creating poorly written code 5 ■ Failing to meet actual needs 6 1.2 Solution: being test-driven 7 High quality with TDD 8 ■ Meeting needs with acceptance TDD 10 ■ What’s in it for me? 11 1.3 Build it right: TDD 14 Test-code-refactor: the heartbeat 15 ■ Developing in small increments 19 ■ Keeping code healthy with refactoring 24 ■ Making sure the software still works 28 i ii CONTENTS 1.4 Build the right thing: acceptance TDD 31 What’s in a name? 31 ■ Close collaboration 32 ■ Tests as a shared language 33 1.5 Tools for test-driven development 36 Unit-testing with xUnit 36 ■ Test frameworks for acceptance TDD 37 ■ Continuous integration and builds 37 ■ Code coverage 39 1.6 Summary 41 Beginning TDD 43 2 2.1 From requirements to tests 45 Decomposing requirements 45 ■ What are good tests made of? 47 ■ Working from a test list 47 ■ Programming by intention 48 2.2 Choosing the first test 48 Creating a list of tests 49 ■ Writing the first failing test 50 ■ Making the first test pass 54 ■ Writing another test 56 2.3 Breadth-first, depth-first 58 Faking details a little longer 59 ■ Squeezing out the fake stuff 60 2.4 Let’s not forget to refactor 63 Potential refactorings in test code 64 ■ Removing a redundant test 65 2.5 Adding a bit of error handling 66 Expecting an exception 66 ■ Refactoring toward
    [Show full text]
  • Mastering Test-Driven Development (TDD) Using Junit
    Trivera Technologies Explore. Learn. Advance! Collaborative IT Training, Coaching & Skills Development Solutions Mastering Test-Driven Development (TDD) using JUnit Explore JUnit, Testing Apps with Native IDE Support, Use Mock Objects, TDD Best Practices, Refactoring & Much More w w w . t r i v e r a t e c h . c o m Course Snapshot Course: Mastering Test-Driven Development (TDD) using JUnit (TT3500) Duration : 5 days Audience & Skill-Level : This in an introduction to TDD course for experienced Java developers Hands-on Learning: This lab-intensive, hands-on course combines engaging expert lessons, demos and group discussions with real-world, skills-focused machine-based labs and exercises. Student machines are required. Delivery Options : This course is available for onsite private classroom presentation , live online virtual presentation , or can be presented in a blended learning format . Please also ask about our Self-Paced / Video / QuickSkills or Mini-Camp / Short Course flexible delivery options. Public Schedule : This course has active dates on our live-online open enrollment Public Schedule . Customizable : This course agenda, topics and labs can be further adjusted to target your specific training skills objectives, tools and learning goals. Please ask for details. Overview Mastering Test Driven Development using JUnit is a five-day, comprehensive hands-on test-driven development / JUnit / TDD training course geared for developers who need to get up and running with essential Test-driven development programming skills using JUnit and various open-source testing frameworks. Throughout the course you'll learn, explore and gain practcal experience working with best practices for writing great programs in Java, using test-driven development techniques.
    [Show full text]
  • Mastering Test-Driven Development Using Junit Course Description
    Contact Us [email protected] HOME > COURSE CATALOG > ORACLE > JAVA > MASTERING TEST-DRIVEN DEVELOPMENT USING JUNIT Mastering Test-Driven Development using JUnit DURATION 5 Days COURSE EJCJ-520-CZ AVAILABLE FORMATS Classroom Training, Online Training Course Description Overview This Mastering Test-Driven Development using JUnit course is designed to provide students with a five-day, comprehensive hands-on test-driven development / JUnit / TDD training course geared for developers who need to get up and running with essential Test-driven development programming skills, using JUnit and various open-source testing frameworks. Throughout the course students learn the best practices for writing great programs in Java, using test-driven development techniques. This comprehensive course also covers essential TDD topics and skills. Students who attend Mastering Test-Driven Development using JUnit will leave the course armed with the skills they require to develop solid Java programs, using sound coding testing techniques and best coding practices. This course quickly introduces developers to the features of JUnit and educates them regarding JUnit’s strengths and weaknesses. 9/26/2021 1 of 6 9:22:18 PM The following JUnit-based testing frameworks are examined: JUnit 4.x EasyMock PowerMock jWebUnit DBUnit This course is one step in the following Learning Journey: 1. Java - Core Objectives Upon completion of the Mastering Test-Driven Development using JUnit course, students will be able to: Test basic Java functionality Test web-functionality implemented in JEE Use mocks for needed resources Replace mocks and test database operations Integrate the layers of the application using Spring and testing as they progress Understand JUnit.
    [Show full text]
  • Unit Testing Essentials Using Junit 5 and Easymock (With
    Trivera Technologies IT Training Coaching Courseware Collaborate. Educate. Accelerate! Unit Testing Essentials using JUnit 5 and EasyMock (with Best Practices) Explore Unit Testing, JUnit, Best Practices, Testing Apps with Native IDE Support, Debugging, Using EasyMock & More w w w . t r i v e r a t e c h . c o m Course Snapshot Course: Unit Testing Essentials using JUnit 5 and EasyMock (TT3524) Duration: 3 days Audience & Skill‐Level: This in an introduction to Unit Testing course for experienced Java developers Language / Tools: This course uses JUnit 5 and EasyMock. This course is also available for JUnit 4, or JUnit 5 and Mocktio. Hands‐on Learning: This course is approximately 50% hands‐on, combining expert lecture, real‐world demonstrations and group discussions with machine‐based practical labs and exercises. Student machines are required. Delivery Options: This course is available for onsite private classroom presentation, live online virtual presentation, or can be presented in a flexible blended learning format for combined onsite and remote attendees. Please also ask about our Self‐ Paced / Video or QuickSkills / Short Course options. Public Schedule: This course has active dates on our live‐online open enrollment Public Schedule. Customizable: This course agenda, topics and labs can be further adjusted to target your specific training skills objectives, tools and learning goals. Please inquire for details. Overview JUnit 5 and EasyMock make it possible to write higher‐quality Java code. These powerful tools are designed to support robust, predictable and automated testing development in the Java enterprise application arena. Unit Testing Essentials using JUnit 5 and EasyMock is a three‐day, hands‐on unit testing course geared for experienced developers who need to get up and running with essential unit testing skills using JUnit, EasyMock, and other tools.
    [Show full text]
  • Software Testing Trying Hard to Make Software Fail
    Software Testing Trying Hard to Make Software Fail Ludovic Court`es Service d'exp´erimentation& d´eveloppement 7 June 2011 1 Introduction 2 Practicalities Running Tests What to Test? When Write Tests? 3 Beyond to find & isolate bugs to make sure bugs get fixed to make sure bugs don't come back Want your software to be studied for its bugs? Why Test? \Faults in Linux: Ten Years Later", Palix et. al, 2010 http://faultlinux.lip6.fr/ to find & isolate bugs to make sure bugs get fixed to make sure bugs don't come back Why Test? Want your software to be studied for its bugs? \Faults in Linux: Ten Years Later", Palix et. al, 2010 http://faultlinux.lip6.fr/ to make sure bugs get fixed to make sure bugs don't come back Want your software to be studied for its bugs? \Faults in Linux: Ten Years Later", Palix et. al, 2010 http://faultlinux.lip6.fr/ Why Test? to find & isolate bugs to make sure bugs don't come back Want your software to be studied for its bugs? \Faults in Linux: Ten Years Later", Palix et. al, 2010 http://faultlinux.lip6.fr/ Why Test? to find & isolate bugs to make sure bugs get fixed Want your software to be studied for its bugs? \Faults in Linux: Ten Years Later", Palix et. al, 2010 http://faultlinux.lip6.fr/ Why Test? to find & isolate bugs to make sure bugs get fixed to make sure bugs don't come back 1 Introduction 2 Practicalities Running Tests What to Test? When Write Tests? 3 Beyond \Determining success or failure of tests must be an automatic process." | B.
    [Show full text]
  • Java Test Driven Development with Junit 5 Course Summary
    "Charting the Course ... ... to Your Success!" Java Test Driven Development with JUnit 5 Course Summary Description Test Driven Development (TDD) has become a standard best practice for developers, especially those working in an Agile development environment. TDD is a team and individual code development discipline which, when followed correctly, increases the productivity of both individual developers and entire teams. From the programmer’s perspective, TDD has another benefit – it allows programmers to eliminate the tedious tasks of debugging and rewriting code so that they can focus on the creative work of designing and writing code. It makes programming fun again. The course focuses on two main topic streams. The first is how to start using the TDD process and inte-grate it into code development or maintenance activities. The best practices for TDD are covered in depth including explanations on why these are best practices. This stream concludes with an introduction into the practice of how TDD is used to refactor and improve existing code as well as code under development. The second stream is tool oriented. Students learn the features of the new JUnit 5 tool through a hands on exploration of the framework, as well as exploring some of the common assertion and mocking libraries. The class is designed to be about 50% hands on labs and exercises, about 25% theory and 25% instructor led hands on learning where students code along with the instructor. The course closes with students developing an action plan for implementing what they
    [Show full text]
  • Mockito Programming Cookbook I
    Mockito Programming Cookbook i Mockito Programming Cookbook Mockito Programming Cookbook ii Contents 1 Mockito Tutorial for Beginners 1 1.1 What is mocking?...................................................1 1.1.1 Why should we mock?............................................1 1.2 Project creation....................................................2 1.3 Mockito installation..................................................4 1.3.1 Download the JAR..............................................4 1.3.2 With build tools................................................5 1.3.2.1 Maven...............................................5 1.3.2.2 Gradle...............................................5 1.4 Base code to test...................................................6 1.5 Adding behavior...................................................7 1.6 Verifying behavior..................................................8 1.6.1 Verify that method has been called......................................8 1.6.2 Verify that method has been called n times.................................8 1.6.3 Verify method call order...........................................9 1.6.4 Verification with timeout........................................... 10 1.7 Throwing exceptions................................................. 10 1.8 Shorthand mock creation............................................... 11 1.9 Mocking void returning methods........................................... 12 1.10 Mocking real objects: @Spy............................................. 14 1.11 Summary......................................................
    [Show full text]
  • Regression Testing of Transcompiled Cross-Platform Applications
    Regression Testing of Transcompiled Cross-Platform Applications Dissertation der Mathematisch- und Naturwissenschaftlichen Fakult¨at der Eberhard Karls Universit¨atT¨ubingen zur Erlangung des Grades eines Doktors der Naturwissenschaften (Dr. rer. nat.) vorgelegt von Dipl.-Inform. Matthias Hirzel aus M¨unsingen T¨ubingen 2018 Gedruckt mit Genehmigung der Mathematisch-Naturwissenschaftlichen Fakult¨at der Eberhard Karls Universit¨atT¨ubingen. Tag der m¨undlichen Qualifikation: 20.09.2018 Dekan: Prof. Dr. Wolfgang Rosenstiel 1. Berichterstatter: Prof. Dr. Herbert Klaeren 2. Berichterstatter: Prof. Dr. Torsten Grust Abstract Regression testing is a well-accepted and widely used way to ensure that already existing functionality still works as expected when code has been modified in order to realize new features or to resolve known bugs. To this end, devel- opers re-execute previously created tests and check whether these tests still pass. However, depending on the application, regression testing might be very time consuming. This already applies when testing small units, but plays a more and more decisive role when integrated functions and especially end-to- end tests (such as UI or web tests) have to be re-executed. In the worst case, executing all the tests takes several days or even weeks. Consequently, it takes far too much time to get feedback about test failures. In order to solve this problem, researches have presented many different techniques. Originally, these techniques have been tailor-made for standard desktop applications. With the dawn of web applications, it has turned out that the approaches available so far are not directly applicable to web applications. So more and more researches have attended to the special challenges to realize regression testing techniques for this new kind of application.
    [Show full text]
  • A Large Scale Evaluation of Automated Unit Test Generation Using Evosuite
    A A Large Scale Evaluation of Automated Unit Test Generation Using EvoSuite Gordon Fraser, Department of Computer Science, University of Sheffield, Regent Court, 211 Portobello S1 4DP, Sheffield, UK Gordon.Fraser@sheffield.ac.uk Andrea Arcuri, Certus Software V&V Center at Simula Research Laboratory, P.O. Box 134, Lysaker, Norway [email protected] Research on software testing produces many innovative automated techniques, but because software testing is by necessity incomplete and approximate, any new technique faces the challenge of an empirical assessment. In the past, we have demonstrated scientific advance in automated unit test generation with the EVOSUITE tool by evaluating it on manually selected open source projects or examples that represent a particular problem addressed by the underlying technique. However, demonstrating scientific advance is not necessarily the same as demonstrating practical value: Even if EVOSUITE worked well on the software projects we selected for evaluation, it might not scale up to the complexity of real systems. Ideally, one would use large “real-world” software systems to minimize the threats to external validity when evaluating research tools. However, neither choosing such software systems nor applying research prototypes to them are trivial tasks. In this paper we present the results of a large experiment in unit test generation using the EVOSUITE tool on 100 randomly chosen open source projects, the 10 most popular open source projects according to the SourceForge website, 7 industrial projects, and 11 automatically generated software projects. The study confirms that EVOSUITE can achieve good levels of branch coverage (on average 71% per class) in practice. However, the study also exemplifies how the choice of software systems for an empirical study can influence the results of the experiments, which can serve to inform researchers to make more conscious choices in the selection of software system subjects.
    [Show full text]