Programming Scala

Total Page:16

File Type:pdf, Size:1020Kb

Programming Scala Prepared exclusively for sam kaplan What Readers Are Saying About Programming Scala This books speaks directly to developers faced with the real and hard problems of concurrency. It offers clear solutions for building actors on the JVM. John Heintz Principal, Gist Labs Venkat introduces (Java) developers to programming Scala in an easy- to-follow, pragmatic style. This book covers Scala from basics to con- currency, one of the most critical and most difficult topics in program- ming today. Venkat gets to the meat without any fluff, and I highly recommend this book to get you up to speed on Scala quickly. Scott Leberknight Chief architect, Near Infinity Corporation Once again Venkat has made learning easy and fun. With his conver- sational style, this book allows developers to quickly learn the Scala language, its uniqueness, and how it can be best utilized in a multi- language environment. Ian Roughley Consultant, Down & Around, Inc. Multicore processors demand that developers have a solid grounding in the functional programming concepts found at the core of Scala. Venkat provides a great guide to get you started with this exciting new language. Nathaniel T. Schutta Author, speaker, teacher A pleasure to read! A great introduction to Scala for the experienced Java developer! This book teaches the “Scala way” of programming from a Java, object-oriented perspective. Very thorough yet concise. Albert Scherer Software architect, Follett Higher Education Group, Inc. Download at Boykma.Com Prepared exclusively for sam kaplan Concurrency is the next giant challenge we must face as develop- ers, and traditional imperative languages make it too hard. Scala is a functional language on the JVM that offers easy multithreading, con- cise syntax, and seamless Java interop. This book guides Java devel- opers through the important capabilities and nuances of Scala, show- ing why so much interest is bubbling around this new language. Neal Ford Software architect/meme wrangler, ThoughtWorks, Inc. Programming Scala is concise, easy to read, and thorough...one of the best introductions to Scala currently available. It’s a must-read for the programmer who wants to stay relevant as we enter the era of ubiqui- tous multicore processing. This is one of the books that I will go back to, time and again, in the coming years. Arild Shirazi Senior software developer, CodeSherpas, Inc. Download at Boykma.Com Prepared exclusively for sam kaplan Download at Boykma.Com Prepared exclusively for sam kaplan Programming Scala Tackle Multicore Complexity on the JVM Venkat Subramaniam The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Download at Boykma.Com Prepared exclusively for sam kaplan Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragprog.com Copyright © 2008 Venkat Subramaniam. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-10: 1-934356-31-X ISBN-13: 978-1-934356-31-9 Printed on acid-free paper. P1.0 printing, June 2009 Version: 2009-7-7 Download at Boykma.Com Prepared exclusively for sam kaplan Contents 1 Introduction 11 1.1 Why Scala? .......................... 11 1.2 What’s Scala? ........................ 14 1.3 Functional Programming .................. 19 1.4 What’s in This Book? .................... 22 1.5 Who Is This Book For? ................... 24 1.6 Acknowledgments ...................... 24 2 Getting Started 26 2.1 Downloading Scala ..................... 26 2.2 Installing Scala ....................... 27 2.3 Take Scala for a Ride .................... 28 2.4 Scala on the Command Line ................ 30 2.5 Running Scala Code as a Script .............. 31 2.6 Scala from an IDE ...................... 32 2.7 Compiling Scala ....................... 32 3 Getting Up to Speed in Scala 34 3.1 Scala as Concise Java ................... 34 3.2 Scala Classes for Java Primitives ............. 37 3.3 Tuples and Multiple Assignments ............. 38 3.4 Strings and Multiline Raw Strings ............ 40 3.5 Sensible Defaults ...................... 41 3.6 Operator Overloading .................... 43 3.7 Scala Surprises for the Java Eyes ............. 45 4 Classes in Scala 53 4.1 Creating Classes ....................... 53 4.2 Defining Fields, Methods, and Constructors . 54 4.3 Extending a Class ...................... 57 4.4 Singleton Object ....................... 58 4.5 Stand-Alone and Companion Objects .......... 60 4.6 static in Scala ........................ 61 Download at Boykma.Com Prepared exclusively for sam kaplan CONTENTS 8 5 Sensible Typing 63 5.1 Collections and Type Inference .............. 64 5.2 The Any Type ........................ 66 5.3 More About Nothing ..................... 67 5.4 Option Type ......................... 68 5.5 Method Return Type Inference .............. 69 5.6 Passing Variable Arguments (Varargs) .......... 70 5.7 Variance of Parameterized Type .............. 71 6 Function Values and Closures 75 6.1 Moving from Normal to Higher-Order Functions . 75 6.2 Function Values ....................... 76 6.3 Function Values with Multiple Parameters . 78 6.4 Currying ........................... 80 6.5 Reusing Function Values .................. 81 6.6 Positional Notation for Parameters ............ 83 6.7 Execute Around Method Pattern ............. 84 6.8 Partially Applied Functions ................ 87 6.9 Closures ........................... 88 7 Traits and Type Conversions 91 7.1 Traits ............................. 91 7.2 Selective Mixins ....................... 94 7.3 Decorating with Traits ................... 95 7.4 Method Late Binding in Traits ............... 97 7.5 Implicit Type Conversions ................. 99 8 Using Collections 103 8.1 Common Scala Collections ................. 103 8.2 UsingaSet .......................... 104 8.3 Using a Map ......................... 106 8.4 UsingaList ......................... 108 8.5 The for Expression ..................... 113 9 Pattern Matching and Regular Expressions 116 9.1 Matching Literals and Constants ............. 116 9.2 Matching a Wildcard .................... 117 9.3 Matching Tuples and Lists ................. 118 9.4 Matching with Types and Guards ............. 119 9.5 Pattern Variables and Constants in case Expressions . 120 9.6 Pattern Matching XML Fragments ............ 121 9.7 Matching Using case Classes ............... 121 Download at Boykma.Com Report erratum Prepared exclusively for sam kaplan this copy is (P1.0 printing, June 2009) CONTENTS 9 9.8 Matching Using Extractors ................. 124 9.9 Regular Expressions .................... 128 9.10 Regular Expressions as Extractors ............ 129 10 Concurrent Programming 131 10.1 Promote Immutability .................... 131 10.2 Concurrency Using Actor .................. 133 10.3 Message Passing ....................... 137 10.4 The Actor Class ....................... 139 10.5 The actor Method ...................... 141 10.6 receive and receiveWithin Methods ............ 144 10.7 react and reactWithin Methods .............. 146 10.8 loop and loopWhile ..................... 151 10.9 Controlling Thread of Execution ............. 153 10.10 Choosing Among the Receive Methods .......... 154 11 Intermixing with Java 156 11.1 Using Scala Classes in Scala ............... 156 11.2 Using Java Classes in Scala ................ 159 11.3 Using Scala Classes in Java ................ 161 11.4 Extending Classes ...................... 165 12 Unit Testing with Scala 167 12.1 Using JUnit ......................... 167 12.2 Using ScalaTest ....................... 169 12.3 Start with a Canary Test .................. 169 12.4 Using Runner ........................ 170 12.5 Asserts ............................ 172 12.6 Exception Tests ....................... 174 12.7 Sharing Code Between Tests ................ 176 12.8 Functional Style with FunSuite .............. 178 12.9 Running ScalaTests Using JUnit ............. 179 13 Exception Handling 183 13.1 Exception Handling ..................... 183 13.2 Mind the Catch Order ................... 186 14 Using Scala 187 14.1 The Net Asset Application ................. 187 14.2 Getting Users’ Input .................... 187 14.3 Reading and Writing Files ................. 188 14.4 XML as a First-Class Citizen ................ 190 Download at Boykma.Com Report erratum Prepared exclusively for sam kaplan this copy is (P1.0 printing, June 2009) CONTENTS 10 14.5 Reading and Writing XML ................. 193 14.6 Getting Stock Prices from the Web ............ 196 14.7 Making
Recommended publications
  • Java (Programming Langua a (Programming Language)
    Java (programming language) From Wikipedia, the free encyclopedialopedia "Java language" redirects here. For the natural language from the Indonesian island of Java, see Javanese language. Not to be confused with JavaScript. Java multi-paradigm: object-oriented, structured, imperative, Paradigm(s) functional, generic, reflective, concurrent James Gosling and Designed by Sun Microsystems Developer Oracle Corporation Appeared in 1995[1] Java Standard Edition 8 Update Stable release 5 (1.8.0_5) / April 15, 2014; 2 months ago Static, strong, safe, nominative, Typing discipline manifest Major OpenJDK, many others implementations Dialects Generic Java, Pizza Ada 83, C++, C#,[2] Eiffel,[3] Generic Java, Mesa,[4] Modula- Influenced by 3,[5] Oberon,[6] Objective-C,[7] UCSD Pascal,[8][9] Smalltalk Ada 2005, BeanShell, C#, Clojure, D, ECMAScript, Influenced Groovy, J#, JavaScript, Kotlin, PHP, Python, Scala, Seed7, Vala Implementation C and C++ language OS Cross-platform (multi-platform) GNU General Public License, License Java CommuniCommunity Process Filename .java , .class, .jar extension(s) Website For Java Developers Java Programming at Wikibooks Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few impimplementation dependencies as possible.ble. It is intended to let application developers "write once, run ananywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to rurun on another. Java applications ns are typically compiled to bytecode (class file) that can run on anany Java virtual machine (JVM)) regardless of computer architecture. Java is, as of 2014, one of tthe most popular programming ng languages in use, particularly for client-server web applications, witwith a reported 9 million developers.[10][11] Java was originallyy developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems'Micros Java platform.
    [Show full text]
  • Not-Dead-Yet--Java-On-Desktop.Pdf
    NOT DEAD YET Java on Desktop About me… Gerrit Grunwald 2012… The desktop is dead… …the future of applications… …is the Web ! 8 years later… My application folder… My applications folder (future) My applications folder (reality) ??? Seems desktop is not dead ! But what about Java ? Available Toolkits AWT Abstract Window Toolkit Abstract Window Toolkit Since 1995 Cross Platform Platform dependent Bound to native controls Interface to native controls SWT Standard Window Toolkit Standard Window Toolkit Based on IBM Smalltalk from 1993 Cross Platform Platform dependent Wrapper around native controls Java Swing Successor to AWT Java Swing Since Java 1.2 (1998) Cross Platform Platform independent Introduced Look and Feels Emulates the appearance of native controls Java FX Script Intended successor to Swing Java FX Script Since Java 1.6 (2008) Cross Platform Platform independent No Java Syntax Declarative way to describe UI's (based on F3 from Chris Oliver) Java FX Successor to Swing Java FX Since Java 7 (2011) Cross Platform Platform independent Port from JavaFX Script to Java Not part of the Java SE distribution since Java 11 Most of these are still in use… Is Java FX dead ? Is Java FX dead ? Open Sourced as OpenJFX (openjfx.io) Driven by the community Can run on mobile using Gluon technology (gluonhq.com) Can run on web using JPro technology (jpro.one) Actively developed and is getting new features too Where does Java on Desktop suck ? Lack of 3rd party controls Swing had great support over years, JavaFX lacks behind Missing features… e.g.
    [Show full text]
  • Scala Tutorial
    Scala Tutorial SCALA TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Scala Tutorial Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. Scala has been created by Martin Odersky and he released the first version in 2003. Scala smoothly integrates features of object-oriented and functional languages. This tutorial gives a great understanding on Scala. Audience This tutorial has been prepared for the beginners to help them understand programming Language Scala in simple and easy steps. After completing this tutorial, you will find yourself at a moderate level of expertise in using Scala from where you can take yourself to next levels. Prerequisites Scala Programming is based on Java, so if you are aware of Java syntax, then it's pretty easy to learn Scala. Further if you do not have expertise in Java but you know any other programming language like C, C++ or Python, then it will also help in grasping Scala concepts very quickly. Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] TUTORIALS POINT Simply Easy Learning Table of Content Scala Tutorial ..........................................................................
    [Show full text]
  • Top 19 Testng Interview Questions & Answers
    https://career.guru99.com/ Guru99 Provides FREE ONLINE TUTORIAL on Various courses like Java | MIS | MongoDB | BigData | Cassandra | Web Services ------------------------------------------------------------------------------------------------------------------------------- SQLite | JSP | Informatica | Accounting | SAP Training | Python ------------------------------------------------------------------------------------------------------------------------------- Excel | ASP Net | HBase | Testing | Selenium | CCNA | NodeJS ------------------------------------------------------------------------------------------------------------------------------- TensorFlow | Data Warehouse | R Programming | Live Projects | DevOps ------------------------------------------------------------------------------------------------------------------------------- Top 19 TestNG Interview Questions & Answers Following are frequently asked questions in interviews for freshers as well as experienced TestNG professionals. 1) What is TestNG? TestNG is an automated open source testing framework. It is based on JUnit framework but is not a JUnit extension. 2) What are the TestNG features? TestNG features include TestNG uses more OO (object-oriented) and Java features It supports testing integrated classes Different Annotations are supported Separate compile time test code from data info /run time configuration Run-time configuration is flexible Flexible plug-in API For further flexibility embeds BeanShell Multi-threaded selenium testing support Supports parallel testing,
    [Show full text]
  • Scala for the Impatient
    Scala for the Impatient Copyright © Cay S. Horstmann 2012. All Rights Reserved. The evolution of Java and C++ has slowed down considerably, and programmers who are eager to use more modern language features are looking elsewhere. Scala is an attractive choice; in fact, I think it is by far the most attractive choice for programmers who want to move beyond Java or C++. Scala has a concise syntax that is refreshing after the Java boilerplate. It runs on the Java virtual machine, providing access to a huge set of libraries and tools. It embraces the functional programming style without abandoning object-orientation, giving you an incremental learning path to a new paradigm. The Scala interpreter lets you run quick experiments, which makes learning Scala very enjoyable. And, last but not least, Scala is statically typed, enabling the compiler to find errors, so that you don't waste time finding them later in running programs (or worse, don't find them). I wrote this book for impatient readers who want to start programming with Scala right away. I assume you know Java, C#, or C++, and I won't bore you with explaining variables, loops, or classes. I won't exhaustively list all features of the language, I won't lecture you about the superiority of one paradigm over another, and I won't make you suffer through long and contrived examples. Instead, you will get the information that you need in compact chunks that you can read and review as needed. Scala is a big language, but you can use it effectively without knowing all of its details intimately.
    [Show full text]
  • Programming Groovy.Pdf
    What readers are saying about Programming Groovy More than a tutorial on the Groovy language, Programming Groovy is an excellent resource for learning the advanced concepts of metaob- ject programming, unit testing with mocks, and DSLs. This is a must- have reference for any developer interested in learning to program dynamically. Joe McTee Developer, JEKLsoft Venkat does a fantastic job of presenting many of the advanced fea- tures of Groovy that make it so powerful. He is able to present those ideas in a way that developers will find very easy to internalize. This book will help Groovy developers take their kung fu to the next level. Great work, Venkat! Jeff Brown Member, the Groovy and Grails development teams At this point in my career, I am really tired of reading books that introduce languages. This volume was a pleasant breath of fresh air, however. Not only has Venkat successfully translated his engaging speaking style into a book, he has struck a good balance between introductory material and those aspects of Groovy that are new and exciting. Java developers will quickly grasp the relevant concepts without feeling like they are being insulted. Readers new to the plat- form will also be comfortable with the arc he presents. Brian Sletten Zepheira, LLC You simply won’t find a more comprehensive resource for getting up to speed on Groovy metaprogramming. Jason Rudolph Author, Getting Started with Grails This book is an important step forward in mastering the language. Venkat takes the reader beyond simple keystrokes and syntax into the deep depths of “why?” Groovy brings a subtle sophistication to the Java platform that you didn’t know was missing.
    [Show full text]
  • Advanced-Java.Pdf
    Advanced java i Advanced java Advanced java ii Contents 1 How to create and destroy objects 1 1.1 Introduction......................................................1 1.2 Instance Construction.................................................1 1.2.1 Implicit (Generated) Constructor.......................................1 1.2.2 Constructors without Arguments.......................................1 1.2.3 Constructors with Arguments........................................2 1.2.4 Initialization Blocks.............................................2 1.2.5 Construction guarantee............................................3 1.2.6 Visibility...................................................4 1.2.7 Garbage collection..............................................4 1.2.8 Finalizers...................................................5 1.3 Static initialization..................................................5 1.4 Construction Patterns.................................................5 1.4.1 Singleton...................................................6 1.4.2 Utility/Helper Class.............................................7 1.4.3 Factory....................................................7 1.4.4 Dependency Injection............................................8 1.5 Download the Source Code..............................................9 1.6 What’s next......................................................9 2 Using methods common to all objects 10 2.1 Introduction...................................................... 10 2.2 Methods equals and hashCode...........................................
    [Show full text]
  • Proof of Concept (Poc) Selenium Web Driver Based Automation Framework
    e-ISSN (O): 2348-4470 Scientific Journal of Impact Factor (SJIF): 4.72 p-ISSN (P): 2348-6406 International Journal of Advance Engineering and Research Development Volume 4, Issue 7, July -2017 Proof of concept (Poc) selenium web driver based Automation framework B AJITH KUMAR Master of science ( Information Technology ) Department of Mathematics COLLEGE OF ENGINNERING GUINDY (CEG) Anna university ABSTRACT: To control test execution time. Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifyingthat a software program or application or product: Meets the business and technical requirements that guided it’s design and development. Works as expected. KEY WORDS: SOFTWARE TESTING .AUTOMATION TESTING ,SELENIUM, SELENIUM WEBDRIVER ,AGILE TESTING , TESTNG Test automation : In software testing, test automation is the use of special software (separate from the software being tested) to control the execution of tests and the comparison of actual outcomes with predicted outcomes. Test automation can automate some repetitive but necessary tasks in a formalized testing process already in place, or add additional testing that would be difficult to perform manually. AGILE TESTING : A software testing practice that follows the principles of agile software development is called Agile Testing. Agile is an iterative development methodology, where requirements evolve through collaboration between the customer and self- organizing teams and agile aligns development with customer needs. Selenium automation tool Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser.
    [Show full text]
  • Developing with Pojos: Faster and Easier 3 Chapter 2 ■ J2EE Design Decisions 31
    FROM OUR PEER REVIEW ... “Chris Richardson targets critical design issues for lightweight Java enterprise applications using POJOs with fantastic in-depth exam- ples. This book extends Martin Fowler’s great book, Enterprise Architecture Patterns, as well as the more recent Domain-Driven Design by Eric Evans, by providing practical design guidance and useful examples. It also addresses the architecture and design issues asso- ciated with Spring and Hibernate development, whereas Man- ning’s companion ‘in Action’ books focus primarily on the Spring and Hibernate technologies. “This is a powerful book for architects, senior developers, and consultants. It uniquely combines best practices and design wisdom to integrate domain-driven design and test-driven development for object-oriented Java enterprise applications using lightweight Spring, Hibernate, and JDO technologies. “The table of contents reflects the important topics that most architects and enterprise developers face every day. There is signifi- cant need for a book like this, which shows how to address many common and complex design issues with real-world examples. The content in this book is unique and not really available elsewhere.” DOUG WARREN Software Architect Countrywide Financial “POJOs in Action fills a void: the need for a practical explanation of the techniques used at various levels for the successful building of J2EE projects. This book can be compared with the less enterprise- oriented and more abstract J2EE Development without EJB by Rod Johnson, but Richardson offers a step-by-step guide to a successful J2EE project. The explanations of the various alternatives available for each step provide the main thrust of this book.
    [Show full text]
  • 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]
  • Object Oriented Paradigm/Programming
    an object is an instantiation from a class, e.g., you have a pet cat, who's Object Oriented Paradigm name is Garfield, then Garfield is a object (of the class cat) to invoke an method, simply do obj.method( ) or obj->method( ), the Ming- Hwa Wang, Ph.D. former is object reference syntax, and the latter is pointer syntax Department of Computer Engineering Santa Clara University Relationships a-kind-of relationship: a subclass inherits and adds more attributes Object Oriented Paradigm/Programming (OOP) and/or methods from its super class to become somewhat "specialized" similar to Lego, which kids build new toys from assembling the existing is-a relationship: an object of a subclass is an object of its super class construction blocks of different shapes part-of relationship: OOP - doing programs by reusing (composing/inheriting) objects has-a relationship: (instantiated from classes) as much as possible, and only writing code when no exiting objects can be applied Reusability inheritance Two Fundamental Principles for OOP a sub/child/derived/extended class can inherit all properties from its generalization or reusability: the classes designed should target to super/parent/base/original class, with or without reusability, i.e., it should very generic and can be applied to lots of modification/override or addition situations/applications without much efforts; reusability comes from single inheritance and multiple inheritance (watch out naming inheritance and/or composition conflicts) encapsulation or information hiding: we can hide detailed or composition implementation specific information away from the users/programmers, so changing implementation using the same interfaces will not need Abstract or Virtual Classes modifying the application code only used as a super class for other classes, only specified but not fully defined, and can't be instantiated OOP Language vs.
    [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]