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.
Tag Archives: TestNG
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.
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:
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:
In this article, we will go through the TestNG HTML and XML reports.
We will be doing the following:
- 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.
- Go through the TestNG report model.
- Examine TestNG provided default reports that are created by default in the directory
- In the end, implement a custom report using
Let’s start with the setup:
- I am using using Maven as the build tool and Eclipse as the IDE, version Luna 4.4.1.
- TestNG Maven Project Example will guide you on how to setup a Maven based project and run the TestNG tests.
Table Of Contents
- 1. TestNG Report Project
- 2. Report Model
- 3. TestNG Default Reports
- 4. Main Report Layout
- 5. Emailable Report
- 6. Old Suite Html Reporter
- 7. TestNg.xml just for the failed Tests
- 8. TestNG Results in XML
- 9. JUnit XML Reports
- 10. Progressive Html Report for Individual Tests
- 11. Custom Report
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
Before we start with the examples, a bit about the setup:
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.