Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to use the Fields() function in Golang?
The strings package of Golang provides a Fields() method, which can be used to split a string around one or more instances of consecutive whitespace characters.The Fields() function splits a given string into substrings by removing any space characters, including newlines. And it treats multiple consecutive spaces as a single space.Syntaxfunc Fields(s string) []stringWhere s is the string parameter.ExampleLet us consider the following example −package main import ( "fmt" "strings" ) func main() { // Initializing the Strings string1 := " The Golang Programming Language " // Display the Strings fmt.Println("Input String:", string1) ...
Read MoreWhat is the EqualFold function in Golang?
The EqualFold() function in Golang is an inbuilt function of strings package which is used to check whether the given strings (UTF-8 strings) are equal. The comparison is not case-sensitive. It accepts two string parameters and returns True if both the strings are equal under Unicode case-folding (i.e., case-insensitive), False otherwise.Syntaxfunc EqualFold(s, t string) boolWhere s and t are strings. It returns a Boolean value.ExampleThe following example demonstrates how to use EqualFold() in a Go program −package main import ( "fmt" "strings" ) func main() { // Intializing the Strings R := "Welcome to Tutorialspoint" ...
Read MoreHow to count the number of repeated characters in a Golang String?
Count() is a built-in function is Golang that can be used to count the number of non-overlapping instances of a character/string in a string.Syntaxfunc Count(s, sep string) intWhere, s – Original Stringsep – Substring which we want to count.It returns an Integer value.ExampleThe following example demonstrates how you can use the Count() function in a Go program.package main import ( "fmt" "strings" ) func main() { // Initializing the Strings x := "Golang Programming Language" y := "Language" // Display the Strings fmt.Println("First String:", x) fmt.Println("Second String:", y) ...
Read MoreHow to use Contains() function in Golang?
Golang has a set of built-in string functions that we can utilize to perform different types of operations on string data. Contains() is such a function that can be used to search whether a particular text/string/character is present in a given string. If the text/string/character is present in the given string, then it returns True; else it returns False.Syntaxfunc Contains(s, substr string) boolWhere, s is the original string and substr is the string which is to be checked with the original string.ExampleThe following example demonstrates how Contains() works −package main // importing fmt and strings import ( "fmt" ...
Read MoreHow to get the result status from TestNG in @AfterMethod?
TestNG supports native dependency injection. It allows to declare additional parameters in methods. At the runtime, TestNG automatically fills these parameters with the right values. Here is a list of some native dependencies in TestNG:ITestContextXmlTestMethodITestResultYou can use these dependencies to get the execution status of a test in TestNG.Usually, @AfterMethod supports all these native dependencies and the test status could be either Success, Failure or Skip.TestNG supports the following test status that can be retrieved by calling the function at the right place.org.testng.ITestResultpublic static final intFAILURE2public static final intSKIP3public static final intSTARTED16public static final intSUCCESS1public static final intSUCCESS_PERCENTAGE_FAILURE4In this article, ...
Read MoreHow to make TestNG print a detailed message about a failure?
TestNG supports a lot of assertions. It has the org.testng.Assert class that extends the Java object class java.lang.object.Whenever there is a failure, a user would want to get a detailed failure report in order to perform a root cause analysis. But, sometimes the displayed failure information is not sufficient and sometimes the user is supplied with the same type of failure information repeated every time. These kinds of issues can be handled in TestNG using the keyword verbose ="".TestNG supports verbose and allows the user to pass a value based on the extent of failure information they want to see. ...
Read MoreHow to execute a single test from a large testing suite using TestNG.xml?
testNG.xml is very flexible and it can work as a harness file to execute the test cases. It keeps the development and execution separate from each other. A user can develop "N" number of test cases in testNG but can run a limited number of test methods based on the configuration in testNG.xml.In this article, let's see how to run only one test method from a large TestNG suite.To run only one test method, we will use the 'include' keyword from TestNG. In testNG.xml, first we will define the class name where the method is present and after that mention ...
Read MoreHow to turn off TestNG's default reporters programmatically?
TestNG allows to run the test suites from IntelliJ IDE as well as from the command line. When user runs the testNG.xml either from an IDE or the command line, TestNG generates a default report. It saves all the reports and respective HTML files in the Project->test-output folder. If this folder does not exist, then TestNG creates one.To disable the default reports programmatically, TestNG should be run through the command line (cmd).Following are the prerequisites to run the test suites from the command line −testNG.xml file should be created to define the test suites and testing classes to execute.All the ...
Read MoreHow to use TestNG SkipException?
TestNG supports multiple ways to skip or ignore a @Test execution. Based on requirement, a user can skip a complete test without executing it at all or skip a test based on a specific condition. If the condition meets at the time of execution, it skips the remaining code in the test.Following are the ways to skip a @Test execution −Use the parameter enabled=false at @Test. By default, this parameter is set as True.Use throw new SkipException(String message) to skip a test.Conditional Skip − The user can have a condition check. If the condition is met, it will throw SkipException ...
Read MoreHow to assert that two Lists are equal with TestNG?
TestNG supports a lot of assertions. It has the org.testng.Assert class, which extends the Java object class java.lang.object.To compare two lists specifically, TestNG's Assert class has a method known as assertEquals(Object actual, Object expected) and there is an extended version of this method with customized message as assertEquals(Object actual, Object expected, String message).This method returns True if −both the objects are Lists, both the lists are of same size, andif the elements of the lists are in the same order.If any of these conditions are not True, it will return False.In this article, we will discuss how to compare two ...
Read More