Package: pyosmo
pyosmoA simple model-based testing (MBT) tool for pythonOriginal OSMO tester can be found from:https://github.com/mukatee/osmoMotivationPyosmo is very useful tool when need to test system under testing logic very carefully or long time with automation.
This tool maximises the MBT tool flexibility and power by using the the pure python code as modelling language.From traditional testing tools perspective pyosmo provides automated test case creation based on programmed model. In
practise parametrized test cases (for
example:pytest parametrized fixtures)
are providing a bit similar functionality than simple test model can do. With true model it is able to plan a lot more
complex scenarions.From traditionalModel-based testingtools perspective pyosmo is
providing much more flexible modelling language and simple integration to the system under testing or test generator.
Traditionally MBT tools have been using graphical modelling language which leads the stat explosion when test data is
included to the model. In pyosmo the model is pure python. Then it is able to model anything that is able to code with
python. All python libraries are helping the modelling work.Installusing pippipinstallpyosmoor using git clonegitclonegit@github.com:OPpuolitaival/pyosmo.git
python-mpipinstall-e.Example modelimportpyosmoclassExampleCalculatorModel:def__init__(self):print('starting')self._counter=0defbefore_test(self):self._counter=0defguard_decrease(self):returnself._counter>1defstep_decrease(self):self._counter-=1print(f"-{self._counter}")defguard_increase(self):returnself._counter<100defstep_increase(self):self._counter+=1print(f"+{self._counter}")# Initialize Osmo with modelosmo=pyosmo.Osmo(ExampleCalculatorModel())# Generate testsosmo.run()Select your approachOffline model-based testing (MBT)This means that the model will generate test cases which can be executed later using your existing test infrastructure.Checkout the examplePros:Maximum reuse of existing test harnessOsmo runs once and generated tests can be execute multiple times same wayOsmo can generate short tests for smoke and long tests for regression testingCons:The model cannot evolve based on system under testing responsesCannot test non-deterministic systemsCannot run "infinite"Online model-based testingOnline MBT means that when model steps are executed also real command are sent to the system and responses returned to
the model.Pros:Model can be really smart because it may evolve based on the systemEnable non-deterministic systems testingTest can take as long as neededCons:Typically need more experiences of modellingCannot reuse existing test harness so easilyUse casesRegression testingimportpyosmo# This ues same example model than defined aboveosmo=pyosmo.Osmo(ExampleCalculatorModel())# Make sure that osmo go trough whole model in every test caseosmo.test_end_condition=pyosmo.end_conditions.StepCoverage(100)# Do some test cases, which test do not take too longosmo.test_suite_end_condition=pyosmo.end_conditions.Length(3)# Give seed to make sure that test is same every timeosmo.seed=333# Run osmoosmo.generate()Long running testimportdatetimeimportpyosmoosmo=pyosmo.Osmo(ExampleCalculatorModel())# Run model for ten hoursosmo.test_end_condition=pyosmo.end_conditions.Time(int(datetime.timedelta(hours=10).total_seconds()))osmo.test_suite_end_condition=pyosmo.end_conditions.Length(1)osmo.generate()Run with pytestimportpyosmo# You can use your existing fixtures normallydeftest_smoke():osmo=pyosmo.Osmo(ExampleCalculatorModel())osmo.test_end_condition=pyosmo.end_conditions.Length(10)osmo.test_suite_end_condition=pyosmo.end_conditions.Length(1)osmo.algorithm=pyosmo.algorithm.RandomAlgorithm()osmo.generate()Performance testingWhen system behaviour is modelled in online models you can usehttps://locust.io/to run multiple models parallel for stress test purposes. It may need