TECH

March 29, 2024

Create a CSS layout with CSS Grid and Flexbox.

CSS Layout is important in web design as it determines how elements are positioned on a webpage. CSS Grid and Flexbox have made designing layouts easier. This post explores the concepts of CSS Grid and Flexbox, their differences, and when to use each one.

View More
TECH

March 29, 2024

Higher-order Functions in the Javascript

Higher-order functions are the functions that operate on other functions by taking them as parameters or returning them. Simply put, a higher-order function is a function that takes other functions as arguments or returns functions as their results.

Higher-order functions are widely used in Javascript. Here are some Higher-order functions built into Javascript that you have probably come across:

View More
TECH

March 28, 2024

Mocking in Python's Unittest

Mocking is a powerful technique in unit testing that allows developers to simulate the behavior of complex dependencies or external systems. In Python's unittest framework, the unittest.mock module provides robust support for creating and working with mock objects. This topic delves into the concept of mocking and demonstrates its usage within Python's unittest framework.

 

Concept of Mocking:

Mocking involves substituting real objects or functions with simulated versions, known as mock objects. These mock objects mimic the behavior of their real counterparts, allowing developers to isolate components under test from their dependencies. Mocks are programmable and can be configured to return predefined values, raise exceptions, or record interactions.

 

Key Concepts of Mocking:

  • Mock Objects: Mock objects are objects that simulate the behavior of real objects. They can be configured to behave in specific ways and record interactions with them.
  • Patch: Patching is a technique used to replace objects or functions in the code under test with mock objects. This allows developers to control the behavior of dependencies during testing.
  • Assertions: Assertions in unit tests verify that certain conditions are met. Mocks can be used in assertions to verify that specific methods were called with the expected arguments or to check the number of times a method was called.

 

Using Mocking in Python's Unittest:

Python's unittest.mock module provides a flexible framework for creating and working with mock objects. Developers can use the patch() function to replace objects or functions with mock equivalents temporarily. Additionally, assertions such as assert_called_once_with() and assert_called_with() can be used to verify the behavior of mock objects.

 

Advantages of Mocking:

  1. Isolation: Mocking enables the isolation of code under test, facilitating focused testing without reliance on external dependencies.
  2. Flexibility: Mock objects offer flexibility in configuring behaviors, allowing developers to simulate various scenarios and edge cases effortlessly.
  3. Speed: Mocking can expedite testing by eliminating the need to interact with external systems or resources, resulting in faster test execution times.
  4. Enhanced Test Coverage: Mocking empowers developers to test error-handling scenarios and exceptional conditions that may be challenging to reproduce with real dependencies.

 

Limitations of Mocking:

  1. Complexity: Overuse of mocking can lead to overly complex test suites, diminishing readability and maintainability.
  2. Dependency on Implementation: Mocks are tightly coupled to the implementation details of the code under test, making tests susceptible to breaking when implementation changes occur.
  3. Risk of False Positives: Inadequate verification of mock behavior may result in false positives, where tests pass despite incorrect implementations or missing assertions.

 

Best Practices for Effective Mocking:

  1. Focused Testing: Prioritize testing the behavior of the code under test rather than the implementation details of dependencies.
  2. Clear Documentation: Document the purpose and behavior of mock objects to improve code understanding and facilitate collaboration among team members.
  3. Regular Review: Periodically review mock usage to ensure tests remain relevant, maintainable, and aligned with evolving codebases.

 

Example:

Suppose you have a function in your application like the following, which communicates with an external API to retrieve data:

import requests

def get_data_from_api(url):

response = requests.get(url)
if response.status_code == 200:

return response.json()

else:

return None

In testing, you want to verify that the get_data_from_api() function handles situations correctly when the API returns data successfully and when it encounters errors. However, actually calling the API during testing may cause issues such as: time consumption, dependency on network connection, or error-prone behavior.

Instead of making actual calls to the API, you can use the Mocking technique to create a mock object, simulating the API's behavior during testing. Here's an example of how to do this in unittest:

import unittest
from unittest.mock import patch
from my_module import get_data_from_api
 
class TestGetDataFromAPI(unittest.TestCase):
 
@patch('my_module.requests.get')
def test_get_data_success(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.json.return_value = {'data': 'test'}
data = get_data_from_api('http://example.com/api')
self.assertEqual(data, {'data': 'test'})
 
@patch('my_module.requests.get')
def test_get_data_failure(self, mock_get):
mock_get.return_value.status_code = 404
data = get_data_from_api('http://example.com/api')
self.assertIsNone(data)
 
if __name__ == '__main__': unittest.main()
 
In this example, we use the @patch decorator to replace the requests.get function with a mock object. In each test case, we set the expected return values of the mock object (e.g., status_code and json), thereby testing whether the get_data_from_api() function works correctly in both successful and failed cases.

 

Conclusion:

Mocking is a valuable technique in unit testing that enables developers to create reliable and maintainable test suites. By leveraging the capabilities of Python's unittest.mock module, developers can effectively simulate the behavior of dependencies and external systems, leading to more robust and efficient testing practices.

 

References:

View More
TECH

March 27, 2024

What have you gained from the software tester job?

You often hear about what you need to learn to become a tester, but have you ever wondered what you will learn when you are a tester? Besides enhancing specialized skills such as software testing, requirement analysis, and staying updated on new technologies, you can also improve some useful knowledge and skills in life as follows:

Deep Understanding of Various Business Domains

This is truly interesting because few professions can help you understand another industry's business so thoroughly. As a tester in software project, you have the opportunity to read all customer requirements, understand the project's detailed design, and thus comprehend the activities, processes, or specific requirements of a particular organization or industry. While developers may only understand a part of the functionality which they are responsible for. Due to job demands, testers must learn more about the context, operational environment, end-users behavior, security issues, and compliance of the field they are testing in. Therefore, testers accumulate knowledge about various business domains such as banking, logistics, ERP, etc.

Furthermore, because testers test all function of the product, they will have a deep understanding of how business operations are reflected in a software product. They know exactly how real-world data flows will be stored and processed within the software system.

Imagine after testing a material management software system for a manufacturing factory, you will know how the material ordering process works, how purchased materials are categorized and stored, how to calculate the quantity of materials for each production line, how to calculate inventory, and the appropriate time to reorder new materials... You may even understand the production process better than an employee of that factory. This is amazing!

 

 

Improving Communication Skills

In the world of developing a software product, developers are builders; they create code that makes everything work. Testers are detectives; they verify the correctness of the product, accompanied by a list of errors that developers need to fix. It is frustrating to be pointed out errors and have to fix them; especially those not mentioned in the design but must be done according to the tester's suggestion. Therefore, testers and developers are often seen as two opposing sides.

When starting out as a tester, it is hard to avoid arguments and conflicts. However, over times, to persuade and prevent arguments with developers, testers practice the ability to express opinions, provide feedback, and report clearly, understandably, and convincingly. They also learn to listen, share information, exchange ideas, and resolve conflicts constructively. This significantly improves their communication and persuasive skills.

Viewing Problems from Various Perspectives

To ensure that the testing process is comprehensive and reliable, throughout the work, testers must test the product from various perspectives. As a good tester, you not only test what is mentioned in the design but also have to stand from the end-user's perspective to think whether your software is user-friendly, helps them operate faster... You not only test the software when it operates under good conditions but also test it under poor conditions. You need to create various test scenarios. This helps you develop a multidimensional mindset for solving different life problems. 

 

In summary, as a tester, you not only contribute to the development of software, bring many useful experiences for end-users but also learn and improve many good skills for your life.

 

Ready to take your testing journey to the next level?

Reach out to IVC to explore practical QA methods and tailored guidance for software testers.

Contact IVC for a Free Consultation

Image source:

https://www.freepik.com/free-vector/disruptive-education-globe-background-vector-geography-digital-remix_17213285.htm#fromView=search&page=1&position=26&uuid=33b4ecf5-cd4b-4d6d-b917-6213ca1bf6d7

https://www.freepik.com/free-vector/flat-design-erp-illustration_25561035.htm#fromView=search&page=1&position=8&uuid=ebbdf32b-5bf8-433d-a85e-8dc413076bdd

https://www.freepik.com/free-photo/representation-user-experience-interface-design_94963704.htm#fromView=search&page=2&position=29&uuid=4ef0f53a-05c6-42d4-adda-7102f1ac25b2

https://www.freepik.com/free-photo/programmers-questioning-source-cyber-attacks-system-security-coverage-software-technician-triangulates-hacker-location-by-updating-safety-script-codes-data-processor-sequencer_25474009.htm#fromView=search&page=1&position=24&uuid=c8164e4a-0cb7-41c8-9492-953b98fbb71d

View More
TECH

March 26, 2024

Some array sorting issues and solutions in ReactJS

To sort the data array, we can use many methods. Incorrect selection can lead to errors that are difficult to detect with uniform, standard-format test data. I would like to share some errors and solutions that I have encountered in a React project, as follows:

View More
TECH

March 22, 2024

What is Google Cloud Search ?

Your company is using Google Workplace, You have many information in Gmail, Google Drive, Google Calendar, Google Contacts and others alike. Suddenly, you remember you need to find some information, and you don't remember where that information is in Google Workplace. Google Cloud Search is is what you need in this case.

View More
TECH

March 22, 2024

NextJS: Encrypt Cookie-Based sessions with NodeJS Crypto module

Cookie-base is one of the primary uses for session management. It is easy to implement, suits smaller applications, and has a lower server load but may offer less security than others.
As cookies are susceptible to client-side security risks, the key to safeguarding user information from unauthorized access is to carefully encrypt the sensitive data before storing it in the cookie. This way, even if a cookie is stolen, the data inside remains unreadable.

View More
TECH

March 20, 2024

Be Confident with Data Security: Introducing Microsoft Azure's KeyVault.

In today's digital world, data security has become a top priority for businesses and organizations.
Microsoft Azure, one of the world's leading cloud computing platforms, has introduced a powerful solution to this problem, which is a KeyVault. 

View More
TECH

March 19, 2024

Building A Basic Real-Time Application with Socket.io in Node.js and React.js

In today's digital age, real-time communication has become a crucial aspect of web applications. Whether it's for live chats, collaborative editing, or dynamic data updates, users expect instantaneous responses. Achieving this functionality is made possible by technologies like Socket.io, particularly when combined with the power of Node.js on the backend and React.js on the frontend.

View More
TECH

February 27, 2024

Enhancing Coding Experience: The Value of ChatGPT for Programmers

In the dynamic world of technology, programmers encounter a diverse array of challenges. These range from debugging intricate code to devising innovative solutions for software development projects. Amidst this complexity, ChatGPT emerges as a valuable companion for programmers, offering several advantages to streamline and enhance their coding experience.

View More
1 15 16 17 18 19 22