🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Unit Testing Model Logic
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

OCL is used in MDriven for model constraints, derived attributes and associations, ViewModel definitions, UI visible/enabled expressions, action-enable expressions, and state-machine guards.

Constraints and OCL

OCL is declarative and is expected to be without side effects. In MDriven, a constraint that evaluates to false is broken. Constraints may be presented to users as Information, Warning, or Error.

MDriven also provides OCL operators for accessing constraints and their brokenness. Constraints automatically appear in ViewModels, although they can be opted out per ViewModel.

See Training:Constraints for constraint definitions, severities, delete constraints, and constraint evaluation.

Checking model logic

When checking a model rule, define the expected condition as an OCL constraint or derivation and verify its result using model data. OCL training material also introduces the MDriven Debugger and describes obtaining immediate results from modeling work.

Keep the expected behavior explicit:

Element Check
Constraint Whether the constraint is broken for the relevant model data.
Derived attribute or association Whether the derived value or relationship matches the expected result for the model data.
ViewModel or UI expression Whether the OCL-based presentation, visibility, enabled state, or style expression has the expected result.

Automated and programmatic tests

The supplied documentation does not provide a supported procedure for automated unit tests that instantiate MDriven model objects programmatically or evaluate OCL through a .NET test framework. In particular, it does not document xUnit, NUnit, package references, or an OCL evaluation API.

Do not treat the available OCL and constraint documentation as a framework-specific automated-test guide without confirming the supported runtime and API approach.

See also