SlideShare a Scribd company logo
WE NEED A BETTER
TESTING FRAMEWORK
NOAM TENNE
$ WHOAMI
HACKING AROUND FOR THE PAST ~15 YEARS
VANMOOF
@NOAMTENNE
GITHUB.COM/NOAMT
MEDIUM.COM/@NOAMT
BestCompany
Ever!!1
$ CONFESSION
NIMOY
$ FIND . -NAME | GREP TDD
DO YOU TDD?
DO YOU BDD?
$ FIND . -NAME | GREP BDD
$ WHICH BDD
SCENARIO: DESCRIPTION
GIVEN: A STATE
WHEN: AN ACTION IS PERFORMED
EXPECT: AN OUTCOME
$ VIM BEHAVE.FEATURE
Feature: This is behave
Scenario: Run something
Given we use behave
When we write specs
Then behave runs them
$ VIM STEPS/BEHAVE_STEPS.PY
from behave import given, when, then, step
@given('we use behave')
def step_impl(context):
pass
@when('we write specs')
def step_impl(context):
assert True != False
@then('behave runs them')
def step_impl(context):
assert context.failed is False
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with given:
pass
with expect:
pass
$ VIM NIMOY_SPEC.PY End with _spec.py
Extend
Specification
Contain steps
using “with”
$ VIM NIMOY_SPEC.PY
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with setup:
pass
with expect:
pass
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with setup:
pass
with when:
pass
with then:
pass
$ VIM NIMOY_SAR_SPEC.PY
$ VIM NIMOY_SAR_SPEC.PY
Look, mom!
No asserts!
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with setup:
a = 5
with when:
a = a + 1
with then:
a == 6
$ FIND . -NAME | GREP DDT
DO YOU DDT?
$ WHICH DDT
SCENARIO: DESCRIPTION
GIVEN: A STATE
WHEN: AN ACTION IS PERFORMED
EXPECT: AN OUTCOME
WHERE: VARIABLES EQUAL VALUES
$ VIM TEST_PYTEST_PARAMS.PY
import pytest
@pytest.mark.parametrize("script,result", [
("2 * 21", 42),
("int(0.1337 * 10000)", 1337),
])
def test_eval(script, result):
assert eval(script) == result
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self, value_a, value_b):
with given:
a = value_a
b = value_b
with expect:
(a * b % 2) == 0
with where:
value_a | value_b
2 | 5
2 | 21
$ VIM NIMOY_MATRIX_SPEC.PY
Declare
variables
Variables
Provided
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = value_of_a
b = value_of_b
with expect:
(a * b % 2) == 0
with where:
value_of_a | value_of_b
2 | 5
2 | 21
$ VIM NIMOY_MATRIX_SPEC.PY
Declare
variables
Inject
anywhere
$ VIM NIMOY_LIST_SPEC.PY
from nimoy.specification import Specification
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = value_of_a
b = value_of_b
with expect:
(a * b % 2) == 0
with where:
value_of_a = [2, 2]
value_of_b = [5, 21]
$ FIND . -NAME | GREP MOCK
DO YOU
MOCK?
$ VIM UNITTEST_MOCKS.PY
from unittest import mock
from mock import Mock
def test_mocks():
teh_mock = Mock()
teh_mock.do_it()
assert teh_mock.do_it.call_count == 1
teh_mock.do_another.return_value = 5
assert teh_mock.do_another() == 5
from nimoy.specification import Specification
from unittest.mock import Mock
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = Mock()
with when:
a.method_call() >> 5
with then:
a.method_call() == 5
a.method_call() == 5
$ VIM NIMOY_MOCK_STAGING_RETURN_VALUE.PY
Constant
return value
from nimoy.specification import Specification
from unittest.mock import Mock
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = Mock()
with when:
a.method_call() << [5, 6, 7]
with then:
a.method_call() == 5
a.method_call() == 6
a.method_call() == 7
$ VIM NIMOY_MOCK_STAGING_SIDE_EFFECT.PY
Side effect
from nimoy.specification import Specification
from unittest.mock import Mock
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = Mock()
with when:
a.method_call('argument')
with then:
1 * a.method_call('argument')
$ VIM NIMOY_MOCK_SPEC.PY
No. Of
invocations
Target mock
Expected
arguments
$ VIM NIMOY_MOCK_SPEC.PY
Any no. of
invocations
from nimoy.specification import Specification
from unittest.mock import Mock
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = Mock()
with when:
a.method_call('argument')
with then:
_ * a.method_call('argument')
from nimoy.specification import Specification
from unittest.mock import Mock
class ExampleSpec(Specification):
def example_feature(self):
with given:
a = Mock()
with when:
a.method_call('argument')
with then:
_ * a.method_call(_)
$ VIM NIMOY_MOCK_SPEC.PY
Any arg
value
$ FIND . -NAME | GREP SUGAR
JUST
SHOWING OFF
$ VIM EXPECTING_EXCEPTIONS.PY
from nimoy.specification import Specification
class MySpec(Specification):
def my_feature_method(self):
with given:
# Setup
with when:
raise Exception('Whaaaaat')
with then:
err = thrown(Exception)
str(err[1]) == 'Whaaaaat'
$ VIM REGEX.PY
from nimoy.specification import Specification
class MySpec(Specification):
def regex_assertion(self):
with given:
exp = 'The quick brown fox'
with expect:
exp @ '.+brown.+'
This is a valid regex evaluation
$ WHICH NIMOY
PYTHON 3
UNITTEST
AST
github.com/browncoat-ninjas/nimoy
Version: 0.0.1b7
Search Medium for “Building Nimoy”
QUESTIONS?
THANKS!

More Related Content

KEY
BDD with Behat and Symfony2
katalisha
 
PDF
Elixir/OTP for PHP developers
Ignacio Martín
 
KEY
Decent exposure: Controladores sin @ivars
Leonardo Soto
 
PDF
Wake up Neo... Dependencies have you
Ivan Mosiev
 
PDF
Effective akka scalaio
shinolajla
 
PDF
Adam Dangoor - Verified Fakes of Web Services
Adam Dangoor
 
PDF
We Need A Better Testing Framework
noamt
 
PDF
Introduction to BDD (Behavior-Driven Development)
Juan Rodríguez
 
BDD with Behat and Symfony2
katalisha
 
Elixir/OTP for PHP developers
Ignacio Martín
 
Decent exposure: Controladores sin @ivars
Leonardo Soto
 
Wake up Neo... Dependencies have you
Ivan Mosiev
 
Effective akka scalaio
shinolajla
 
Adam Dangoor - Verified Fakes of Web Services
Adam Dangoor
 
We Need A Better Testing Framework
noamt
 
Introduction to BDD (Behavior-Driven Development)
Juan Rodríguez
 

Similar to We Need A Better Testing Framework (2019) (6)

PDF
Digital RSE: automated code quality checks - RSE group meeting
Henry Schreiner
 
PPTX
Testing with Python, Pytest and Vim
Maximilian Jackson
 
PDF
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
PDF
Princeton Wintersession: Software Quality Assurance Tooling
Henry Schreiner
 
PDF
Tools That Help You Write Better Code - 2025 Princeton Software Engineering S...
Henry Schreiner
 
PDF
Python course lecture slides specifications and testing
MuhammadIfitikhar
 
Digital RSE: automated code quality checks - RSE group meeting
Henry Schreiner
 
Testing with Python, Pytest and Vim
Maximilian Jackson
 
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
Princeton Wintersession: Software Quality Assurance Tooling
Henry Schreiner
 
Tools That Help You Write Better Code - 2025 Princeton Software Engineering S...
Henry Schreiner
 
Python course lecture slides specifications and testing
MuhammadIfitikhar
 
Ad

More from noamt (6)

PDF
Go Modules
noamt
 
PDF
Functional Groovy
noamt
 
PDF
Python Peculiarities
noamt
 
PDF
HTTPBuilder NG: Back From The Dead
noamt
 
PDF
Groovy Powered Clean Code
noamt
 
PDF
Searching for the grail
noamt
 
Go Modules
noamt
 
Functional Groovy
noamt
 
Python Peculiarities
noamt
 
HTTPBuilder NG: Back From The Dead
noamt
 
Groovy Powered Clean Code
noamt
 
Searching for the grail
noamt
 
Ad

Recently uploaded (20)

PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Presentation about variables and constant.pptx
kr2589474
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 

We Need A Better Testing Framework (2019)

  • 1. WE NEED A BETTER TESTING FRAMEWORK NOAM TENNE
  • 2. $ WHOAMI HACKING AROUND FOR THE PAST ~15 YEARS VANMOOF @NOAMTENNE GITHUB.COM/NOAMT MEDIUM.COM/@NOAMT BestCompany Ever!!1
  • 4. $ FIND . -NAME | GREP TDD DO YOU TDD?
  • 5. DO YOU BDD? $ FIND . -NAME | GREP BDD
  • 6. $ WHICH BDD SCENARIO: DESCRIPTION GIVEN: A STATE WHEN: AN ACTION IS PERFORMED EXPECT: AN OUTCOME
  • 7. $ VIM BEHAVE.FEATURE Feature: This is behave Scenario: Run something Given we use behave When we write specs Then behave runs them
  • 8. $ VIM STEPS/BEHAVE_STEPS.PY from behave import given, when, then, step @given('we use behave') def step_impl(context): pass @when('we write specs') def step_impl(context): assert True != False @then('behave runs them') def step_impl(context): assert context.failed is False
  • 9. from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with given: pass with expect: pass $ VIM NIMOY_SPEC.PY End with _spec.py Extend Specification Contain steps using “with”
  • 10. $ VIM NIMOY_SPEC.PY from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with setup: pass with expect: pass
  • 11. from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with setup: pass with when: pass with then: pass $ VIM NIMOY_SAR_SPEC.PY
  • 12. $ VIM NIMOY_SAR_SPEC.PY Look, mom! No asserts! from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with setup: a = 5 with when: a = a + 1 with then: a == 6
  • 13. $ FIND . -NAME | GREP DDT DO YOU DDT?
  • 14. $ WHICH DDT SCENARIO: DESCRIPTION GIVEN: A STATE WHEN: AN ACTION IS PERFORMED EXPECT: AN OUTCOME WHERE: VARIABLES EQUAL VALUES
  • 15. $ VIM TEST_PYTEST_PARAMS.PY import pytest @pytest.mark.parametrize("script,result", [ ("2 * 21", 42), ("int(0.1337 * 10000)", 1337), ]) def test_eval(script, result): assert eval(script) == result
  • 16. from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self, value_a, value_b): with given: a = value_a b = value_b with expect: (a * b % 2) == 0 with where: value_a | value_b 2 | 5 2 | 21 $ VIM NIMOY_MATRIX_SPEC.PY Declare variables Variables Provided
  • 17. from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with given: a = value_of_a b = value_of_b with expect: (a * b % 2) == 0 with where: value_of_a | value_of_b 2 | 5 2 | 21 $ VIM NIMOY_MATRIX_SPEC.PY Declare variables Inject anywhere
  • 18. $ VIM NIMOY_LIST_SPEC.PY from nimoy.specification import Specification class ExampleSpec(Specification): def example_feature(self): with given: a = value_of_a b = value_of_b with expect: (a * b % 2) == 0 with where: value_of_a = [2, 2] value_of_b = [5, 21]
  • 19. $ FIND . -NAME | GREP MOCK DO YOU MOCK?
  • 20. $ VIM UNITTEST_MOCKS.PY from unittest import mock from mock import Mock def test_mocks(): teh_mock = Mock() teh_mock.do_it() assert teh_mock.do_it.call_count == 1 teh_mock.do_another.return_value = 5 assert teh_mock.do_another() == 5
  • 21. from nimoy.specification import Specification from unittest.mock import Mock class ExampleSpec(Specification): def example_feature(self): with given: a = Mock() with when: a.method_call() >> 5 with then: a.method_call() == 5 a.method_call() == 5 $ VIM NIMOY_MOCK_STAGING_RETURN_VALUE.PY Constant return value
  • 22. from nimoy.specification import Specification from unittest.mock import Mock class ExampleSpec(Specification): def example_feature(self): with given: a = Mock() with when: a.method_call() << [5, 6, 7] with then: a.method_call() == 5 a.method_call() == 6 a.method_call() == 7 $ VIM NIMOY_MOCK_STAGING_SIDE_EFFECT.PY Side effect
  • 23. from nimoy.specification import Specification from unittest.mock import Mock class ExampleSpec(Specification): def example_feature(self): with given: a = Mock() with when: a.method_call('argument') with then: 1 * a.method_call('argument') $ VIM NIMOY_MOCK_SPEC.PY No. Of invocations Target mock Expected arguments
  • 24. $ VIM NIMOY_MOCK_SPEC.PY Any no. of invocations from nimoy.specification import Specification from unittest.mock import Mock class ExampleSpec(Specification): def example_feature(self): with given: a = Mock() with when: a.method_call('argument') with then: _ * a.method_call('argument')
  • 25. from nimoy.specification import Specification from unittest.mock import Mock class ExampleSpec(Specification): def example_feature(self): with given: a = Mock() with when: a.method_call('argument') with then: _ * a.method_call(_) $ VIM NIMOY_MOCK_SPEC.PY Any arg value
  • 26. $ FIND . -NAME | GREP SUGAR JUST SHOWING OFF
  • 27. $ VIM EXPECTING_EXCEPTIONS.PY from nimoy.specification import Specification class MySpec(Specification): def my_feature_method(self): with given: # Setup with when: raise Exception('Whaaaaat') with then: err = thrown(Exception) str(err[1]) == 'Whaaaaat'
  • 28. $ VIM REGEX.PY from nimoy.specification import Specification class MySpec(Specification): def regex_assertion(self): with given: exp = 'The quick brown fox' with expect: exp @ '.+brown.+' This is a valid regex evaluation
  • 29. $ WHICH NIMOY PYTHON 3 UNITTEST AST