In this post we will learn about TestNG Suite test. A Suite in TestNG is commonly represented by one XML file, usually named as testng.xml. <suite> tag is the first tag in XML file which represents a suite and it may contains one or more <test> tags. Each <test> tag in turn may contain one…
Continue readingAuthor: websystiqueadmin
TestNG Groups Example
In this post we will learn about how to use TestNG groups testing feature using @BeforeGroups, @AfterGroups and group exclusion. TestNG allows us to group several tests together. You can group certain tests based on what behavior/aspect they are actually testing. You may have a scenario where few tests belong to a certain group(say database)…
Continue readingTestNG Annotations Example
In this post we will learn common TestNG annotations including @Test, @BeforeMethod, @AfterMethod, @BeforeClass, @AfterClass, @BeforeGroups, @AfterGroups, @BeforeSuite, @AfterSuite, @BeforeTest & @AfterTest. Further posts next in tutorial explains in detail other popular annotations including @Parameters & @DataProvider annotations. Previous post gave an introduction to TestNG. In this post, we will start using annotations in very…
Continue readingTestNG Hello World Example
In this post we will learn a very basic Hello World example using TestNG. We will learn how to setup environment to use testNG and how to actually write & execute unit tests and verify results. We will be using maven based project. Let’s begin. Following environment being used: TestNG 6.9.4 Maven 3 JDK 1.7…
Continue readingGson Json Annotations Example
Google Gson provides useful annotations which can customize the serialization/deserialization of object to/from JSON. We will see commonly used Google gson annotations including @Expose, @SerializedName, @Since, @Until, & @JsonAdapter, exploring them in detail. First thing first, update project’s pom.xml to include Gson dependency as following: Let’s start now with each annotation: 1) @Expose It is…
Continue readingGson ExclusionStrategy Example
Lets learn Gson ExclusionStrategy and how it can help us.What if you want to exclude some fields from Serialization and Deserialization? Gson provides several ways to handle this scenario.Let’s explore then one-by-one. 1) Using @Expose annotation GsonBuilder’s excludeFieldsWithoutExposeAnnotation() method is a handy way to exclude certain fields from being serialized/deserialized. Just annotate the fields you…
Continue readingGson Custom Serialization Example
Sometimes default serialization/deserialization used by GSON is not sufficient enough and we need a custom behavior to be applied while serializing/deserializing objects to/from JSON. This can easily be done by writing custom JsonSerializer & JsonDeserializer implementation and hooking them with GsonBuilder. We will write a custom implementation to handle a date property in our example…
Continue readingGson Streaming Api Example
Similar to Jackson Streaming API, Google GSON too provides streaming API for the situation where performance is utmost important. Gson Streaming API is based on Sequential read/write and is very useful in situations where it is not desirable to load complete object model in memory(e.g complete data is not available). This is commonly known as…
Continue readingGson Tree Model Example
Similar to Jackson API, Google GSON API provides a conceptual tree notion for JSON. Google Gson Tree model API provides com.google.gson.JsonParser which can be used to parse the input JSON string into a tree of com.google.gson.JsonElement. On reading side, JsonElement provides isJsonXXX methods to check the type of Json element and getAsYYY() methods to get…
Continue readingConverting JSON to/from Java Objects using Google GSON
This post explains converting Java object to/from JSON using Google GSON library. To get hold of JSON Basics concepts, please refer to JSON basics. Let’s get going. com.google.gson.Gson is the main class used for converting JSON to/from java objects. This class provides toJson & fromJson methods to convert Java object to/from JSON. Gson library also…
Continue reading