Thursday, August 15, 2024

Program to count digits in an integer!!!

Given a number N, the task is to return the count of digits in this number.

There are two approaches to get the count of digits in the number N.

Let us see both the approaches:

Approach 1:

We can convert the number into a String and get the length of the string to get the number of digits in the number.

Time Complexity = O(1)

Space Complexity = O(1)

package com.practice.basicprograms;

public class CountOfDigitsinNumber {

public static void main(String[] args) {
int number=18192;
String N=Integer.toString(number);
int length=N.length();
System.out.println(length);
}
}

Approach 2:

  1. Initialize a count variable and increment it by using loop
  2. Run a while loop until N becomes equal or less than 0
  3. Divide N by 10, so that last digit will get eliminated with each iteration
  4. Return the count variable to get the number of digits
package com.practice.basicprograms;

public class CountOfDigitsinNumberUsingLoop {

public static void main(String[] args) {
int n=18192;
CountOfDigitsinNumberUsingLoop counts=new CountOfDigitsinNumberUsingLoop();
System.out.println(counts.countofdigits(n));
}
public int countofdigits(long number){
int count = 0;
while(number!=0){
number=number/10;
count++;
}
return count;
}
}

Time Complexity: O(count of digits)

Space Complexity: O(1)

Happy Coding!!!!

Sunday, October 15, 2023

Different Types of Tests that can be automated🤷‍♂️

Automation can be applied to various types of tests across software development Life cycle, ensuring efficiency, accuracy, and speed in the testing process.


Here are different types of tests that can be automated:

Functional Tests

Functional tests validate the software’s functionality by testing it against the specified requirements. These tests check if the application behaves as expected from the end user’s perspective. Automated functional tests can simulate user interactions and validate various use cases.

Example:

Testing the login functionality of an application with valid credentials.

Unit Tests

Unit test usually tests the individual Object or individual methods of an object in a class. Unit Testing is highly necessary to prevent the flow of defect or preventing the defect at the earliest in the SDLC.

Example:

Testing the loops or conditions in a class

Integration Tests

Integration tests verify the interactions between different components or modules of a system. Several modules are together tested. The purpose of Integration tests is to make sure that all modules integrate and work together as expected. Automated integration tests help ensure that these interactions work as expected and that integrated components function properly together.

Example:

Testing the flow of placing the order for an item in Amazon or Flipkart along with payment.

System Tests

System Testing is a complete fully integrated product Testing. It is an end-to-end testing where the testing environment is similar to the production environment. Here, we navigate through all the features of the software and test if the end business / end feature works. We just test the end feature and don’t check for data flow or do functional testing and all.

Example:

Testing the end to end flow from login to placing and order and rechecking the order in My Orders page and logout in Amazon or Flipkart

Automating these tests can significantly improve the development workflow, allowing for faster feedback, early bug detection, and overall higher software quality. It’s important to strike a balance between automated and manual testing to ensure comprehensive test coverage.

Happy Testing!!!


Saturday, September 23, 2023

Are you new to JavaScript? Have you ever wondered what the difference is between var, const, and let? 

 Understanding the scope, hoisting, and reassignment of variables in JavaScript is crucial for developing robust and maintainable code. 

 In brief, variables declared with var are function-scoped and are hoisted to the top of their containing function or global scope. Reassignment is possible within their scope. 

var a=4

Variables declared with let are block-scoped and are hoisted to the top of their containing block. 
Attempting to access a let variable before its declaration will result in a Reference Error. Reassignment is possible within their block scope. 
let b=5

 Variables declared with const are also block-scoped, but they must be assigned a value when declared, and they cannot be reassigned to a different value after their initial assignment. However, the value itself can be mutable if it's an object or an array. 
const flag=true

 In modern JavaScript, it's recommended to use const by default and only use let when you need to reassign the variable. Avoid using var unless you have a specific reason to use it, as it has some quirks and can lead to unexpected behavior due to its function-scoped nature and hoisting. 

 Remember, using the right variable declaration is essential for writing maintainable and bug-free code.

Saturday, September 9, 2023

Happy Tester’s Day 2023!!!

 Firstly, Happy Testers’ Day!

”Quality is not an act, it is a habit” — Aristotle

 



Imagine a world where software works flawlessly, where products and services meet your expectations and give you a satisfying experience. This is the world we can create with Software testing.

Every IT community requires testers because there would be no one dedicated to identifying issues within the software of a computer, machine, program, or other devices that could cause it to malfunction. However, Quality Assurance is more than just testing; it is also the process of incorporating quality into software development.

Traditionally, Tester’s Day has been observed every year on September 9. On September 9, 1945 when the scientists who were testing the computer Mark II Aiken Relay Calculator, they found a real small moth between the contacts of the electro-mechanical relay and one of them pronounced the word ‘bug’.

The scientists had to make a report on the work done where the term ‘debugging’ appeared for the first time. Now debugging is the process of finding and eliminating bugs which lead to incorrect performance of the system and failures. At that time, the tests were focused on the hardware because it was not as developed as today and its reliability was essential for the proper functioning of the software.

”Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it” — Brian W. Kernighan

The term debugging was associated with the application of a patch for a particular bug as a phase within the stage of software development, and that is why the tests that were performed were only of a corrective nature by taking certain measures in order to make the program work and it was in 1949 when Alan Turing wrote his first article about carrying out checks on a program and then in 1950, in the article “Turing Test”, he explains the situation of how a software must adapt to the requirements of a project and the behavior of a machine or a reference system must be indistinguishable.




However, according to the Yale Book of Quotations, the American inventor Thomas Alva Edison used the term ‘bug’ in a letter to Theodore Puskas in 1878 to describe a flaw in a system.

According to other sources the term bug was commonly used to describe faults in the system during Edison’s time and according to some reports this wasn’t even the first ever computer bug — “It was reported as the first bug in jest, as it was an insect. The term bug had been used as a label for problems in computers and other electrical systems for a long time before this. Grace Hopper did not find the bug. Bill Burke found the bug. Grace Hopper was the team lead and often told the story of its discovery.”


Though people have different assumptions or thoughts for this day, it is important to visualize how the software testing stage has evolved and emerged from its absence to its continuous presence throughout the Software Development Life Cycle. Now we have so many roles and responsibilities within the Testing and it has evolved to a great extent and its all because of a bug found.

Every day is a Tester’s Day, however, it’s acceptable to have an exceptional day that makes testers around the globe share and team up and feel proud to be one. I’d like to congratulate all the people who test software, who strive to make the applications with great quality, passion and wish them all the best!
Happy Tester’s Day to all!

World Tester’s Day is recognized on the 9th of September every year to mark the discovery of the first-ever bug in 1947 since then.

Happy Testing!!!Don’t let any bug escape your sight!

Please share this post with others to inspire them to join us in the world of testing!!! 

Sunday, July 2, 2023

How to Write Good Test Cases?

Writing or Creating Test Cases is one of the important activity performed by the tester in the Software Testing Life Cycle(STLC). But creating effective test cases is an important skill and which can be improved by in depth study of application.

What is test case?

A test case is a set of actions performed on a system to determine if it satisfies software requirements and functions correctly.

Test Cases should be small, isolated and atomic. They should be easy to understand and steps should be clear. Steps should be independent and clear. Each good test should have defined its expected result.

What all fields needs to be included in test case?

1. Test Case ID

Unique Test Case Identification Number

2. Module name or Requirement ID

Module name or Requirement ID mentioned in the System Requirement Document and Traceability Matrix

3. Risks & Assumptions

If any risks or assumptions known 

4. Test Data

Test data required for executing the test case.

5. Test Steps

Detailed steps for test case execution

6. Expected results

How application should behave after executing the above testing steps

7. Result

Pass or Fail

8. Comments

Some additional information for developer to reproduce the defect or some observation.

How To Write Effective Test Cases?

While writing the test cases you need to follow some steps to make sure that you will write good and effective test cases.

  1. Identify The Scope And Purpose Of Testing
  2. Define the testing activities and steps for each testing type
  3. Identify Non-Functional Requirements
  4. Define the automation Test Strategy for Regression
  5. Understand the application in depth.
Important Tips To Write Your Test Cases More Effective:
  1. Test cases should have very good test case coverage.
  2. Test Cases should have good coverage with less no. of steps.
  3. Test Case should be written by applying test case design techniques.
  4. Test Case should be simple to understand.
  5. If test cases given to any new Tester, he/ she should be able to execute the test cases without asking any questions or clarifications.
  6. Test Case should be written in test case template.
  7. Test Case should be consistent, means flow or sequence should be good.
  8. Test Case should consists of both positive and negative scenarios.
  9. Test cases should be able to catch the defects.
  10. Test cases should not be redundant, means no duplicates.
  11. Test Cases should be very easy to convert into Automation scripts.

These are the characteristics of Good Test Case.

Final Thoughts:

A test case is to be written to check if features of application are working as expected. Basically a test case contains Test Case ID, Test Steps, Expected result, Result fields. While writing test case keep in mind that all test cases should be simple and easy to understand. First you should cover the Functional test cases then you should include the non-functional test cases. Both test cases are equally important to improve the quality of application. 

Thanks for reading my article. Hope you liked it!!!

Happy Testing !!!!