Profile

Fabio Ornellas @fabio23


About Me

-

Proposals

[Testing] Open Sourcing The New Test Framework From Facebook

Facebook Production Engineering has a fairly large Python codebase and we require good test coverage. Writing test cases, mocks, patches, is not always easy and can be a big source of frustration. We built a new test framework, TestSlide, that makes mocking easier than ever before. We are proud to open source it at Python Brasil 2018.


TestSlide borrows concepts form other environments, bringing Python testing to the next level. TestSlide has a collection of components, that you can use all together, or stand alone alongside other existing test frameworks.


- StrictMock is a well behaved mock object, that only has the behavior you told it to have. This means, you won't get false results when you run tests, because your mock did something unexpected. It also supports API validation, so it will only have the attributes that the template class has. It also works for magic methods seamlessly.


- To define behavior, mock_callable() does the job for functions and methods. You can define which calls to accept, what to do when the call is received and define assertions on the number of calls. It is composable, so you can define complex behavior using just a few lines. To mock instance creation, you can use mock_constructor(), so you can easily mock your backends for unit testing.


- For TDD / BDD people, fans of frameworks like RSpec, Mocha or Jest, TestSlide's DSL makes you feel at home. With it, you can easily declare complex test scenarios and get an English readable output when you run your tests. This decouples test intent from implementation, making refactoring a breeze when needed.


- TestSlide's Test Runner allows fast iteration cycles when writing code. It has a very readable colored output, specially on failures. It allows to focus execution on a single test, or skip another test, without ever leaving your text editor. Oh, it also works with Python's unittest.TestCase.