A simple and personal comprehensive test suite for my applications.
- Description
- Requirements
- Usage
- Options
- basicCommands.sh Script Details
- TESTS-basicCommands.sh Script Details
- How It All Ties Together
- License
- Author
- Disclaimer
ZoldaxUnitaryTestFramework.sh
is a bash-based test suite tailored to verify the behavior of my applications, ensuring the quality and robustness of the software.
- Bash Shell environment.
- Tested applications and associated test definitions located within the
sample
andTESTS
directories respectively.
./ZoldaxUnitaryTestFramework.sh [-d] [-f script_filename]
-d : Enables debug mode, providing detailed logs during script execution.
-f : Specifies the filename of the script to be tested.
This script behaves differently based on the command-line argument and the existence of certain files.
-
hello: Outputs "Hello, World!" only if a file named
hello.txt
exists in the same directory. If the file doesn't exist, it responds with "Prerequisite not met." -
bye: Responds with "Goodbye!" if a file named
bye.txt
exists in the same directory. In the absence of the file, the script will respond with "Prerequisite not met." -
Any other command will result in "Unknown command."
This script is dedicated to defining a series of tests for our primary script, basicCommands.sh
. Each test is specifically crafted to verify if basicCommands.sh
is producing the expected output based on different input conditions and prerequisites.
Each test follows the format:
"Test Name|Command Option|Expected Output|Setup Commands (if any)"
- Test Name: Descriptive title of what the test is aiming to verify.
- Command Option: The command-line argument that will be passed to
basicCommands.sh
. - Expected Output: What we expect
basicCommands.sh
to produce in response to the given command option. - Setup Commands (if any): These are the prerequisites that need to be executed prior to running the test. They could be commands like creating the necessary
hello.txt
orbye.txt
files.
- Test Hello Command: Aims to verify if the "Hello, World!" message is correctly displayed when the
hello.txt
file is present in the directory. - Test Bye Command: Checks if the script correctly outputs "Goodbye!" when provided with the 'bye' command and when the
bye.txt
file is present. - Test Invalid Command: This test checks the resilience of the script by sending an unknown command and expecting the script to respond with "Unknown command."
The testing framework will use these definitions to:
- Prepare the environment using the setup commands.
- Run the
basicCommands.sh
with the specified command option. - Compare the real-time output with the expected result.
- Provide feedback on whether each test has passed or failed.
By integrating TESTS-basicCommands.sh
with our testing framework, developers can have a streamlined process of verifying that changes or additions to basicCommands.sh
don't inadvertently introduce errors or alter expected behavior. It serves as a safeguard, ensuring that the primary script functions reliably across different scenarios.
$ ./basicCommands.sh hello
The integration between the primary script (basicCommands.sh
) and the test definitions (TESTS-basicCommands.sh
) is what makes this unitary test system effective. Let's delve deeper into how these components interact and orchestrate a robust testing process.
This script is responsible for carrying out the main functionalities. Based on the input command it receives (e.g., hello
, bye
, etc.), it gives specific outputs. However, its output is not just dependent on the input command but also on certain prerequisites – for example, the existence of specific files like hello.txt
or bye.txt
.
For instance:
- When the input is
hello
, the script checks for the existence ofhello.txt
. If the file is present, it returns "Hello, World!", otherwise, "Prerequisite not met." - For the input
bye
, it verifies the presence ofbye.txt
and acts similarly.
This script acts as a catalog of tests for our main script. Every test definition in this script is structured to simulate a specific scenario for basicCommands.sh
.
For each test:
- It sets up the environment (e.g., creating necessary files).
- Executes
basicCommands.sh
with a specific command option. - Checks the output against an expected result.
The test scenarios are designed to cover different aspects of basicCommands.sh
, ensuring that its functionalities are sound and behave as expected across various conditions.
When our testing framework runs:
- It first sources
TESTS-basicCommands.sh
to get all the test definitions. - For each test, it first executes any setup commands.
- Then, it invokes
basicCommands.sh
with the specified command option. - The real-time output is captured and compared with the expected output.
- The framework provides feedback, stating whether the test passed or failed.
Unitary testing, as illustrated here, ensures that every isolated part of basicCommands.sh
functions as expected. As developers introduce changes or additions to basicCommands.sh
, this testing system acts as a safety net, catching potential oversights or errors before they make their way to the final version.
By consistently running these tests, we can ensure the reliability of basicCommands.sh
across different scenarios and make confident decisions during the development phase.
This framework is licensed under the Apache License, Version 2.0. For details, you can review the license here.
Pascal Weber (zoldax)
Contributions are welcome! If you come across any issues or have suggestions, please raise them in the issues section.
All content is without warranty of any kind. Use at your own risk. I assume no liability for the accuracy, correctness, completeness, usefulness, or any damages.