top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Small Discussion about Mockito?

0 votes
384 views

What is Mockito?

Mockito is a mocking framework, JAVA-based library that is used for effective unit testing of JAVA applications. Mockito is used to mock interfaces so that a dummy functionality can be added to a mock interface that can be used in unit testing.

Mocking is a way to test the functionality of a class in isolation. Mocking does not require a database connection or properties file read or file server read to test a functionality. Mock objects do the mocking of the real service. A mock object returns a dummy data corresponding to some dummy input passed to it.

Benefits

  • No Handwriting − No need to write mock objects on your own.
  • Refactoring Safe − Renaming interface method names or reordering parameters will not break the test code as Mocks are created at runtime.
  • Return value support − Supports return values.
  • Exception support − Supports exceptions.
  • Order check support − Supports check on order of method calls.
  • Annotation support − Supports creating mocks using annotation.
Video for Mockito

 

posted Nov 6, 2017 by Manish Tiwari

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

What is JUnit?

JUnit is a unit testing framework for Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks collectively known as xUnit, that originated with JUnit.

JUnit tutorial provides basic and advanced concepts of unit testing in java with examples. Our junit tutorial is designed for beginners and professionals.

It is an open-source testing framework for java programmers. The java programmer can create test cases and test his/her own code.

It is one of the unit testing framework. Current version is junit 4.

To perform unit testing, we need to create test cases. The unit test case is a code which ensures that the program logic works as expected.

The org.junit package contains many interfaces and classes for junit testing such as Assert, Test, Before, After etc.

Features

  • Provides annotations to identify test methods.
  • Provides assertions for testing expected results.
  • Provides test runners for running tests.
  • JUnit tests allow you to write codes faster, which increases quality.
  • JUnit is elegantly simple. It is less complex and takes less time. 

Video for Junit

https://www.youtube.com/watch?v=I8XXfgF9GSc

READ MORE

What is Spring MVC?

The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files. 

The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features.

Spring Web MVC you can use any object as a command or form-backing object; you do not need to implement a framework-specific interface or base class. Spring's data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. 

Thus you need not duplicate your business objects' properties as simple, untyped strings in your form objects simply to handle invalid submissions, or to convert the Strings properly. Instead, it is often preferable to bind directly to your business objects.

Spring's view resolution is extremely flexible. A Controller is typically responsible for preparing a model Map with data and selecting a view name but it can also write directly to the response stream and complete the request. View name resolution is highly configurable through file extension or Accept header content type negotiation, through bean names, a properties file, or even a custom ViewResolver implementation. 

The model (the M in MVC) is a Map interface, which allows for the complete abstraction of the view technology. You can integrate directly with template based rendering technologies such as JSP, Velocity and Freemarker, or directly generate XML, JSON, Atom, and many other types of content. The model Map is simply transformed into an appropriate format, such as JSP request attributes, a Velocity template model.

Spring MVC, like many other web frameworks, is designed around the front controller pattern where a central Servlet, the DispatcherServlet, provides a shared algorithm for request processing while actual work is performed by configurable, delegate components. This model is flexible and supports diverse workflows.

The DispatcherServlet, as any Servlet, needs to be declared and mapped according to the Servlet specification using Java configuration or in web.xml. In turn the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling

Video for Spring MVC

https://www.youtube.com/watch?v=xrExTCcv5Qg​

READ MORE

What is Ant in Java?

Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.

Ant was the first build tool that was created for building Java applications. Ant is implemented in Java, and its build scripts are written in XML. The XML build scripts were easier to understand than the "make" files at that time, so Ant quickly became popular as a build tool among Java developers. Additionally, Ant is an open source project which made it available for free to all developers.

Features

  • Ant is the most complete Java build and deployment tool available.
  • Ant is platform neutral and can handle platform specific properties such as file separators.
  • Ant can be used to perform platform specific tasks such as modifying the modified time of a file using 'touch' command.
  • Ant scripts are written using plain XML. If you are already familiar with XML, you can learn Ant pretty quickly.
  • Ant is good at automating complicated repetitive tasks.
  • Ant comes with a big list of predefined tasks.
  • Ant provides an interface to develop custom tasks.
  • Ant can be easily invoked from the command line and it can integrate with free and commercial IDEs.

Ant is not the only build tool for Java. After Ant came Maven which has standardized how Java projects are built and how dependencies (external JAR files used by your Java project) are managed (specified and downloaded). Today Maven has taken a lot of the popularity that Ant used to have.

 

Video for Ant in Java

https://www.youtube.com/watch?v=Rpe5dkPsBSc

 

READ MORE

What is Jetty?

Jetty is an open-source project providing an HTTP server, HTTP client, and javax.servlet container.

Eclipse Jetty provides a Web server and javax.servlet container, plus support for HTTP/2, WebSocket, OSGi, JMX, JNDI, JAAS and many other integrations. These components are open source and available for commercial use and distribution.

Eclipse Jetty is used in a wide variety of projects and products, both in development and production. Jetty can be easily embedded in devices, tools, frameworks, application servers, and clusters. See the Jetty Powered page for more uses of Jetty.

The current recommended version for use is Jetty 9 which can be obtained on the Jetty Downloads page. Also available are the latest maintenance releases of Jetty 8 and Jetty 7,

The Jetty project has been hosted at the Eclipse Foundation since 2009. Prior releases of Jetty have existed in part or completely under the Jetty project at the The Codehaus and Sourceforge before that. See the About page for more information about the history of Jetty.

Jetty implements aspects of the Java EE specification, primarily the Servlet Specification. Recent releases of the Java EE platform have introduced a Web Profile, recognizing that many developers need only a subset of the many technologies under the Java EE umbrella.

While Jetty itself does not ship all of the Web Profile technologies, Jetty architecture is such that you can plug in third party implementations to produce a container customized to your exact needs.

Video for Jetty Server

https://www.youtube.com/watch?v=lvZfEXqIAyE

READ MORE

What is Jest?

Jest is an open JavaScript testing library from Facebook. Its slogan is "Delightful JavaScript Testing". While Jest can be used to test any JavaScript library, it shines when it comes to React and React Native. 

Main Benefits

     1) Developer Ready

             Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project.

      2) Instant Feedback 

                Fast interactive watch mode runs only test files related to changed files and is optimized to give signal quickly.

      3) Snapshot Testing

               Capture snapshots of React trees or other serializable values to simplify testing and to analyze how state changes over time.

Jest is used by Facebook to test all JavaScript code including React applications. One of Jest's philosophies is to provide an integrated "zero-configuration" experience. 

NPM and Yarn Command for Installation.

npm install --save-dev jest

yarn add --dev jest

Video for JEST Library

https://www.youtube.com/watch?v=7r4xVDI2vho

READ MORE
...