Tag Archives: TestNG

How to test EJB apps with Glassfish embedded container


There are many articles about EJB deploying and testing. But after one of my colleagues spent a week trying to make it work, I decided to write my own. I’ll describe the wrong path first and then correct it.

https://victorlapin.wordpress.com/2015/06/29/how-to-test-ejb-apps-with-glassfish-embedded-container/

How to Implement linked list in Java with JUnit test Example


via How to Implement linked list in Java with JUnit test Example.

In this article we will learn two things, how to implement linked list from scratch in Java and how to write unit test using JUnit framework. Though Java has LinkedList class, which is implementation of doubly linked list, its good to know how to implement singly linked list in Java, mostly to practice coding interview questions. Coming to back to writing unit test, from time to time, I have said that a Java programmer must write unit tests. IMHO, unit testing is the best development practice to improve code quality. Fortunately Java eco system has luxury of great unit testing frameworks in form of JUnit and TestNG, and every Java developer should take advantage of this. Writing unit test is one of the best programming practice along with code review. It’s natural and I had experienced it myself that unit test, not only provides code coverage, but also present unique opportunities for code refactoring. Many times, while writing unit tests, I have discovered better names for my methods and refactored large methods into smaller ones. JUnit tests also helps to organize code and evaluate encapsulation. There is a good chance of you discovering that a particular field or method is exposing implementation detail, and should be abstracted in public method. What all this means is, you, a Java developer, must write unit tests. Since it always helps to start smaller, this JUnit tutorial will present another simple JUnit example to show how to write unit test in Java. In this JUnit tutorial, we will implement linked list in Java and we will write unit test cases for linked list. For those, who are not familiar with linked list, it’s one of the fundamental data structure to store objects, like array, which is also use to store object. By the way, there are many difference between linked list and array data structure, which is subject of another blog post, but main difference is in the way objects are stored. array needs contiguous memory, while linked list doesn’t need that.

Mockito void Method Example


via Mockito void Method Example | Examples Java Code Geeks.

In Mockito Hello World Example, we have learnt how to stub a non-void method that returns something. Sometimes we may also need to stub a void method which is what I am going to show in this article.

Before I start with my example, a bit about my setup:

Mockito Spy Example


via Mockito Spy Example | Examples Java Code Geeks.

In this article, I am going to show you an example of Mockito Spy.

There are times when we would like to use most of the original object’s behavior but mock only a portion of it. This is called spying objects, also called as partial mocking. Before I start with the example, let me first brief you about my setup:

TestNG HTML and XML Reports Example


via TestNG HTML and XML Reports Example | Examples Java Code Geeks.

In this article, we will go through the TestNG HTML and XML reports.

We will be doing the following:

  1. Start with a TestNG project which we will later run to generate reports. We will be running a main suite containing a couple of child suites, this will create enough data for us to review the reports generated.
  2. Go through the TestNG report model.
  3. Examine TestNG provided default reports that are created by default in the directory./test-output.
  4. In the end, implement a custom report using Reporter API.

Let’s start with the setup:

TestNG Parameters Annotation Example


via TestNG Parameters Annotation Example | Examples Java Code Geeks.

Table Of Contents

1. How to use a TestNG parameter?
2. Null Parameter
3. Optional Parameter
4. Method with Multiple Parameters
5. Parameter Types
6. Constructor with Parameters
7. Configuration methods with Parameters
8. Parameters in a Factory method
9. Parameter along with TestNG Injected Objects
10. Parameters passed to a static method
11. Overriding Parameters
12. Inheriting Parameters

A TestNG based test method is like any other java method and is allowed to have parameters. @Parameters is the TestNG annotation that allows us to pass parameters to a Test method.

In this article, I am going to show you several examples of @Parameters annotation.

Before we start with the examples, a bit about the setup:

TestNG Spring Integration Example


via TestNG Spring Integration Example | Examples Java Code Geeks.

In this article, we will go through a few examples of TestNG and spring integration. Before we start with the examples, let me first brief you on the goal of spring’s integration testing framework:

  •  Manage Spring IoC container caching between test execution.
  •  Provide Dependency Injection of test fixture instances.
  • Provide transaction management appropriate to integration testing.

In this article, first I will brief you on Spring TestContext Framework and then I will be showing an example for each of the above case using TestNG as the testing framework.

Below are my setup details:

  • I am using Eclipse as the IDE, version Luna 4.4.1.
  • I will be running the tests using eclipse TestNG plugin so you need to install the TestNG Eclipse Plugin.
  • Since the project depends on spring, TestNG, MySql for the database, we will be creating a Maven based project in eclipse. If you are new to Maven, you may go through the details here.