Develop with ease
Topalov Alex 2017
Test Example
Ruby Warrior
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411866/148477495479062__1_.gif)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3403654/pasted-from-clipboard.png)
Intro
Part 1. Algorithmic Complexity
Flog
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411806/pasted-from-clipboard.png)
Reek
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3415718/pasted-from-clipboard.png)
Flay
Code duplications
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411817/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411821/pasted-from-clipboard.png)
Churn
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411862/pasted-from-clipboard.png)
LOC/NOC
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411874/pasted-from-clipboard.png)
Cyclomatic complexity
Saikuro, RuboCop
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411840/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411843/pasted-from-clipboard.png)
RuboCop
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411865/pasted-from-clipboard.png)
Security
Bundler Audit, Brakeman. *nix security
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411869/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411872/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411873/pasted-from-clipboard.png)
Where to?
1. CodeClimate
2. MetricFu
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411878/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3411880/pasted-from-clipboard.png)
How to?
1. SOLID
2. Patterns
3. Refactoring
SRP
(Single responsibility principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3412985/pasted-from-clipboard.png)
SRP
(Single responsibility principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413007/pasted-from-clipboard.png)
SRP
(Single responsibility principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417362/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417370/pasted-from-clipboard.png)
OCP
(Open/Closed principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413262/pasted-from-clipboard.png)
OCP
(Open/Closed principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413279/pasted-from-clipboard.png)
LSP
(Liskov substitution principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413120/pasted-from-clipboard.png)
LSP
(Liskov substitution principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413187/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413193/pasted-from-clipboard.png)
LSP
(Liskov substitution principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417336/pasted-from-clipboard.png)
ISP
(Interface segregation principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413346/pasted-from-clipboard.png)
ISP
(Interface segregation principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413360/pasted-from-clipboard.png)
ISP
(Interface segregation principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417202/pasted-from-clipboard.png)
DIP
(Dependency invertion principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3415538/pasted-from-clipboard.png)
DIP
(Dependency invertion principle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3413279/pasted-from-clipboard.png)
Part 2. Tests
Code/Test Coverage
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3415600/db6f253e-502d-11e6-9d84-e40c3d75f333.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3415602/db6f9f0a-502d-11e6-816c-edb2c66fad8d.png)
Mutator
(ex Heckle)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3415648/pasted-from-clipboard.png)
How to?
- F.I.R.S.T
- Refactoring
F - Fast
- A developer should not hesitate to run the tests as they are slow.
- All of these including setup, the actual test and tear down should execute really fast (milliseconds) as you may have thousands of tests in your entire project.
I - Isolated/Independent
- Arrange.
- Act.
- Assert.
- Avoid doing asserts in the Arrange part, let it throw exceptions and your test will still fail.
- No order-of-run dependency. They should pass or fail the same way in suite or when run individually.
- Do not do any more actions after the assert statement(s), preferably single logical assert.
R - Repeatable
- A test method should NOT depend on any data in the environment/instance in which it is running or state.
- Deterministic results.
No dependency on date/time or random functions output. - Each test should setup or arrange it's own data.
Use Data Helper classes/Factories/Fabricators that can setup this data for re-usability.
S - Self-Validating
- No manual inspection required to check whether the test has passed or failed.
T - Thorough and Timely
- Should cover every use case scenario and NOT just aim for 100% coverage.
- Should try to aim for Test Driven Development (TDD) so that code does not need re-factoring later.
Part 3. Non-algorithmic Complexity
Learning Curve
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3408427/pasted-from-clipboard.png)
Business requirements
Business requirements
We need a sales report
Business requirements
We need a sales report...
Can we have a date range there
Business requirements
We need a sales report...
Can we have a date range there...
We also need COGS to be present
Business requirements
We need a sales report...
Can we have a date range there...
We also need COGS to be present...
Can we exclude fraud/non-verified customers
Business requirements
We need a sales report...
Can we have a date range there...
We also need COGS to be present...
Can we exclude fraud/non-verified customers...
Is there are a way to see sales from new and returning customers?
Business requirements
We need a sales report...
Can we have a date range there...
We also need COGS to be present...
Can we exclude fraud/non-verified customers...
Is there are a way to see sales from new and returning customers?
Can we also have sales for shipped orders?
Business requirements
We need a sales report...
Can we have a date range there...
We also need COGS to be present...
Can we exclude fraud/non-verified customers...
Is there are a way to see sales from new and returning customers?
Can we also have sales for shipped orders?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417266/pasted-from-clipboard.png)
Further reading:
- 99 Bottles. Good for LSP understanding. Sandi Metz.
- Principles, Patterns, and Practices. Robert Martin(a. k. a. Uncle Bob)
- Integration Tests are a Scam. Joe Rainsberger
- Refactoring from Good to Great. Ben Orenstein
- Refactoring(https://refactoring.guru/). Martin Fowler
![](https://s3.amazonaws.com/media-p.slid.es/uploads/84449/images/3417252/64815677.jpg)
deck
By Alex Topalov
deck
- 1,907