MQL5 lacks native unit testing, so utility bugs in lot sizing, pip value, and normalization often slip into production. This article presents a zero‑dependency framework built from preprocessor assertion macros, interface‑based suites, and a central runner/formatter. It runs as a script in OnStart, executes deterministic tests, and prints pass/fail summaries to the Experts tab to catch rounding, boundary, and error-handling defects before deployment.
Consider a lot-size calculator that computes position volume based on account equity, risk percentage, and stop-loss distance. The function might work perfectly for typical inputs, yet fail silently when the calculated lot falls between two valid lot-step increments and rounds in the wrong direction.
This type of defect will not crash the EA or trigger a terminal error code. It simply submits an order with a volume that is slightly off, quietly distorting the strategy's risk profile over hundreds of trades. Without a formal assertion checking exact outputs against known inputs, these compounding defects remain completely invisible to casual observation.
To bridge this gap, this article builds a native, zero-dependency testing framework. The architecture relies on three structural components:
Preprocessor Assertion Macros: Automatically capture the exact source file and line number at the moment a test fails.
Interface-Based Test Suites: Isolate and group related test logic to maintain a clean development workspace.
A Central Test Runner: Aggregates individual test results and prints a structured pass/fail summary.
The entire system executes as a standard MQL5 script, requires no external tools, and outputs directly to the terminal's Experts tab.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Building a Compile-Time Unit Testing Framework in MQL5 Using Preprocessor Assertions.
MQL5 lacks native unit testing, so utility bugs in lot sizing, pip value, and normalization often slip into production. This article presents a zero‑dependency framework built from preprocessor assertion macros, interface‑based suites, and a central runner/formatter. It runs as a script in OnStart, executes deterministic tests, and prints pass/fail summaries to the Experts tab to catch rounding, boundary, and error-handling defects before deployment.
Consider a lot-size calculator that computes position volume based on account equity, risk percentage, and stop-loss distance. The function might work perfectly for typical inputs, yet fail silently when the calculated lot falls between two valid lot-step increments and rounds in the wrong direction.
This type of defect will not crash the EA or trigger a terminal error code. It simply submits an order with a volume that is slightly off, quietly distorting the strategy's risk profile over hundreds of trades. Without a formal assertion checking exact outputs against known inputs, these compounding defects remain completely invisible to casual observation.
To bridge this gap, this article builds a native, zero-dependency testing framework. The architecture relies on three structural components:
The entire system executes as a standard MQL5 script, requires no external tools, and outputs directly to the terminal's Experts tab.
Author: Ushana Kevin Iorkumbul