Giter Site home page Giter Site logo

cloned-explorejunit5's Introduction

ExploreJunit5

JUnit5 comes with a fresh breathe of air, having junit4 for more than a decade.We had one big Junit4 which was used both by dev tools and build tools. It was becoming outdated nor it was extensible with new tools. JUnit5 is written completely in Java8 but it has backward compatability with test classes written in Junit 4 or Junit3.

NOTE: Any project not using JAVA 8 should NOT consider migrating to Junit5.

Junit5 is modular as well as extensible ,comes with new features and plugins which can be used by different IDE tools or Build tools junit5_arch

Different plugins/jars are packaged with

  • Jupiter engine
  • Vintage engine
  • Third Party engine

figure-1

Here we have worked out with few worked out examples which can highlight the features of JUnit5. Features like

  • New Asserts in Junit5
  • Exploring the power of using @Extension annotations
  • New annotations in Junit5.
  • Using Dynamic test in Junit5
  • Using Repeated test in JUnit5
  • Using Parameterized test in JUnit5
  • Using Parameter Resolver in Junit5

This repository used Maven to build the files and for its execution.Though Gradle can also be used.

Few Important things while updating POM.xml

      
  • For Running old Junit4 Test Classes with JUnit5 framework , we need to add the dependencies for junit-platform-surefire-provider and junit-vintage-engine plugin with maven –surefire-plugin.
  •   
  • To execute Both New JUnit5 and Old JUnit4 Test Classes together in Junit5 framework, we need to add the dependency for junit-jupiter-engine.
  •   
  • To execute only New JUnit5 Test Classes, we need to add the dependency for junit-jupiter-engine and use maven-compiler-plugin to run the test classes.

Currently, IDE like Eclipse, IntelliJ,Netbeans can execute JUnit5 framework by adding @RunWith(JUnitPlatform.class) i.e. junit-platform-runner for executing tests and test suites on the JUnit5 Platform in a JUnit 4 environment(like in Eclipse IDE till it supports JUnit5).

File Information

  • Person : This is an normal POJO class.
  • PersonDao :This interface defines all kind of crud related methods.
  • PersonDaoBean : Implementation of the PersonDao interface.
  • PersonDataStore : Singleton class containing a dump of Person object data.
  • AbstractSpringConfiguration : This is to invoke Spring IOC Container.

Test Related Files

  • GeneratedParameterResolver: This class implements ParameterResolver interface and contains callback methods which will be invoked by any Test Class using the @ExtendWith annotation like @ExtendWith(SimpleJUnitParameterResolver.class).
  • JUnitSpringConfiguration : This is to invoke the Spring IOC in JUnit enviornemnt.
  • PersonDaoBeanDyamicTest: This class will explore many new Junit5 assserts, annotations and most importantly using Dynamic test.
  • PersonDaoBeanRepeatedTest: This class will explore how we can implement new feature of Junit5 i.e. Repeated Test.
  • PersonDaoBeanParameterizedTest: This class will explore the very important feature of Junit5 i.e. Parameterized test using either @MethodSource, @ValueSource or @EnumSource. @EnumSource is left explicitly for your practise.

There are few more Test or call back interfaces are provided.You can explore more or play out with the code and get your hand dirty in Junit5.

Using mvn clean install will compile and execute all the test classes.Alternatively, this files can also be imported to Eclipse or any other IDE.

Here is the screenshot of PersonDaoBeanParameterizedTest when executed in Eclipse will give you a report like below junit_run

cloned-explorejunit5's People

Contributors

jchowdhary avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.