Unit Testing Using Unittest in Python

Hafeezul Kareem
Updated on 24-Apr-2020 12:12:21

973 Views

In this tutorial, we are going to learn about Unit Testing using the unittest built-in module. Testing plays a major role in software development. You will know the issues before going to the production itself.We'll learn the basics of testing in Python using the built-in module called unittest. Let's jump into the tutorial.What is Unit Testing?If you take the login system as an example. Each field in the login form is a unit/component. And testing those units/components functionality is known as Unit Testing.ExampleLet's see the basic structure of unittest framework. Live Demo# importing unittest module import unittest # unittest will test ... Read More

Functions in C/C++

Sunidhi Bansal
Updated on 24-Apr-2020 11:55:57

278 Views

Functions are like a machine as they perform some functionality and produces a result of some type. Like, machine takes some input, process that input and produce an output similarly, function takes some value, operates on those value and produces the output. Manually a person passes the input to the machine then only the machine will start its functionality in the same manner when the programmer calls the function it will start executing.Functions can be different in name in various languages, but they share two common characteristics like −They contain sequence of instructions that needs to be processedThose instructions are ... Read More

Stack in C++ STL

Sunidhi Bansal
Updated on 24-Apr-2020 11:55:29

475 Views

In C++ STL, stack is used as container which is implemented as LIFO structure. LIFO means Last In First Out. Stack can view as a pile of books in which the books are arranged one above the another and the last inserted book will be the first one to be removed that’s why it is called as a LIFO structure.The operations associated with the stack are -Top() - This function returns the reference to the topmost element of a stack.Syntax - name_of_stack.top()Parameters - No ParameterReturn Value - Reference to the topmost element of a stack containerPush() - This function is ... Read More

Boolean Parse Method in C#

AmitDiwan
Updated on 24-Apr-2020 11:11:22

2K+ Views

The Boolean.Parse() method in C# is used to convert the specified string representation of a logical value to its Boolean equivalent.SyntaxFollowing is the syntax −public static bool Parse (string val);Above, the parameter value is a string containing the value to convert.ExampleLet us now see an example to implement the Boolean.Parse() method −using System; public class Demo {    public static void Main(){       bool b;       b = bool.Parse("FALSE");       Console.WriteLine("After parsing = "+b);    } }OutputThis will produce the following output −After parsing = FalseExampleLet us see another example −using System; public class ... Read More

Show Reflection Frames of StackFrame in Java 9

raja
Updated on 24-Apr-2020 10:22:23

202 Views

A standard API has been provided in Java 9 using java.lang.StackWalker class. This class designed to be efficient by allowing lazy access to the stack frames. A couple of other options allow in a stack trace that includes implementation and/or reflection frames, and it can be useful for debugging purposes. For instance, we add SHOW_REFLECT_FRAMES option to StackWalker instance upon creation, so that frames for reflective methods are printed as well.In the below example, we can able to show reflection frames of StackFrameExampleimport java.lang.StackWalker.Option; import java.lang.StackWalker.StackFrame; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.stream.Collectors; public class ReflectionFrameTest {    public static ... Read More

Skip Certain Classes in Stack Frame in Java 9

raja
Updated on 24-Apr-2020 09:20:53

256 Views

StackWalker API has been introduced in Java 9, and it gives a snapshot of the stack trace of current thread at any given point of time and has methods to walk over it. The advantage of using StackWalker class over Thread::getStackTrace() is to filter or skip certain classes and get the instance of declaring the class itself and get either short stack trace or full stack trace instead of pulling the complete stack trace itself.In the below example, we can use java.util.stream.Stream.skip() method to skip Stack Frames.Exampleimport java.lang.StackWalker.*; import java.util.Optional; import java.util.List; import java.util.stream.Collectors; import java.lang.StackWalker.StackFrame; public class StackWalkerSkipTest {    public ... Read More

Define a Switch Statement in JShell in Java 9

raja
Updated on 23-Apr-2020 18:43:42

208 Views

JShell is based on the REPL (Read-Evaluate-Print-Loop) introduced in Java 9. This tool can be used to execute simple statements, evaluate it, and prints the result.A switch statement can test multiple conditions just like an else clause and handles the default possibility. The default clause can be executed when none of the cases match, and a break statement can be used to break out of switch after a successful match.In the below code snippet, we can define the switch statement in JShell.Snippet-1jshell> int i = 10; i ==> 10 jshell> switch(i) { ...> case 1 ... Read More

Use Terminal Stream Operations in JShell in Java 9

raja
Updated on 23-Apr-2020 14:28:12

274 Views

JShell is an interactive tool that takes simple statements, expressions and etc.. as input, evaluates it, and prints the result immediately to the user.Terminal Operation is a stream operation that takes a stream as input and doesn't return any output stream. For instance, a terminal operation can be applied to a lambda expression and returns a single result (A single primitive-value/object, or a single collection-of-objects). The reduce(), max(), and min() methods are a couple of such terminal operations.In the below code snippet, we can use different terminal operations: min(), max(), and reduce() methods in JShell.Snippetjshell> IntStream.range(1, 11).reduce(0, (n1, n2) -> n1 + n2); $1 ... Read More

Get Stack Trace Using Thread in Java 9

raja
Updated on 23-Apr-2020 12:19:48

541 Views

Java 9 has added StackWalker class to provide a standard API for accessing the current thread stack. In the previous java versions, we can use Throwable::getStackTrace, Thread::getStackTrace, and SecurityManager:: GetClassContext provided methods to obtain the thread stack.Thread.getStackTrace() method will return an array of stack trace elements representing the stack dump of a thread (StackTraceElement[]). The first element of an array represents the top of a stack, it can be the last method invocation in a sequence, and the last element of an array represents the bottom of a stack, it can be the first method invocation in a sequence.Syntaxpublic StackTraceElement[] ... Read More

Use Intermediate Stream Operations in JShell in Java 9

raja
Updated on 23-Apr-2020 09:49:02

359 Views

JShell is a tool introduced in Java 9, and it accepts simple statements like expressions, variables, methods, classes, etc.. as input and produces immediate results.A Stream is a sequence of values. An intermediate stream operation is an operation that takes a stream. For instance, it can be applied to a lambda expression and produces another stream of elements as its result.The most popular intermediate stream operations are mentioned below:1) sorted(): This method preserves the elements of the consumed stream as a result but also puts them in natural sorted order.2) distinct(): This method returns a stream retaining only unique elements of the input ... Read More

Advertisements