Slide 1

Slide 1 text

TDD codurance.com Testing anti-patterns

Slide 2

Slide 2 text

Matheus Marabesi Hello there, you can call me Marabesi, But my name is Matheus Marabesi, I work at Codurance as a Software craftsperson. I enjoy talking about anything related to: testing, patterns and gamification. You can find me at @MatheusMarabesi or https://marabesi.com Codurance Crafting Code

Slide 3

Slide 3 text

1. Intro - Background 2. Excessive setup 3. The Liar 4. The giant 5. The slow poke 6. Wrapping up Crafting code Agenda

Slide 4

Slide 4 text

1. Background Warming up Getting started

Slide 5

Slide 5 text

TDD

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

When Test Driven Development Goes Wrong Dave Farley - by Continuous Delivery

Slide 8

Slide 8 text

tddconf.com

Slide 9

Slide 9 text

The Liar The Giant The Mockery The Inspector Generous Leftovers The Local Hero The Nitpicker The Secret Catcher The Dodger The Loudmouth Anti patterns The Greedy Catcher Excessive Setup The Sequencer Hidden Dependency The Enumerator The Stranger The Operating System Evangelist Success Against All Odds The Free Ride The One The Peeping Tom The Slow Poke James Carr - TDD Anti-Patterns

Slide 10

Slide 10 text

The Liar 4 The Giant 5 The Mockery The Inspector Generous Leftovers The Local Hero The Nitpicker The Secret Catcher The Dodger The Loudmouth Anti patterns The Greedy Catcher Excessive Setup 3 The Sequencer Hidden Dependency The Enumerator The Stranger The Operating System Evangelist Success Against All Odds The Free Ride The One The Peeping Tom The Slow Poke 6

Slide 11

Slide 11 text

SSD 14/16: Test Patterns and Anti-Patterns Yegor Bugayenko

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

2. Excessive setup - 🏆3 A test that requires a lot of work setting up in order to even begin testing. Sometimes several hundred lines of code is used to setup the environment for one test, with several objects involved, which can make it difficult to really ascertain what is tested due to the “noise” of all of the setup going on. Crafting code

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

jest.mock('compression') jest.mock('connect') jest.mock('serve-static') jest.mock('serve-placeholder') jest.mock('launch-editor-middleware') jest.mock('@nuxt/utils') jest.mock('@nuxt/vue-renderer') jest.mock('../src/listener') jest.mock('../src/context') jest.mock('../src/jsdom') jest.mock('../src/middleware/nuxt') jest.mock('../src/middleware/error') jest.mock('../src/middleware/timing') Jest - javascript - Nuxtjs

Slide 19

Slide 19 text

describe('server: server', () => { beforeAll(() => { jest.spyOn(path, 'join').mockImplementation((...args) => `join(${args.join(', ')})`) jest.spyOn(path, 'resolve').mockImplementation((...args) => `resolve(${args.join(', ')})`) connect.mockReturnValue({ use: jest.fn() }) serveStatic.mockImplementation(dir => ({ id: 'test-serve-static', dir })) nuxtMiddleware.mockImplementation(options => ({ id: 'test-nuxt-middleware', ...options })) errorMiddleware.mockImplementation(options => ({ id: 'test-error-middleware', ...options })) createTimingMiddleware.mockImplementation(options => ({ id: 'test-timing-middleware', ...options })) // piece of code hidden }) Jest - javascript Jest - javascript - Nuxtjs

Slide 20

Slide 20 text

describe('server: server', () => { beforeAll(() => { jest.spyOn(path, 'join').mockImplementation((...args) => `join(${args.join(', ')})`) jest.spyOn(path, 'resolve').mockImplementation((...args) => `resolve(${args.join(', ')})`) connect.mockReturnValue({ use: jest.fn() }) serveStatic.mockImplementation(dir => ({ id: 'test-serve-static', dir })) nuxtMiddleware.mockImplementation(options => ({ id: 'test-nuxt-middleware', ...options })) errorMiddleware.mockImplementation(options => ({ id: 'test-error-middleware', ...options })) createTimingMiddleware.mockImplementation(options => ({ id: 'test-timing-middleware', ...options })) // piece of code hidden }) Jest - javascript Jest - javascript - Nuxtjs

Slide 21

Slide 21 text

describe('server: server', () => { beforeAll(() => { jest.spyOn(path, 'join').mockImplementation((...args) => `join(${args.join(', ')})`) jest.spyOn(path, 'resolve').mockImplementation((...args) => `resolve(${args.join(', ')})`) connect.mockReturnValue({ use: jest.fn() }) serveStatic.mockImplementation(dir => ({ id: 'test-serve-static', dir })) nuxtMiddleware.mockImplementation(options => ({ id: 'test-nuxt-middleware', ...options })) errorMiddleware.mockImplementation(options => ({ id: 'test-error-middleware', ...options })) createTimingMiddleware.mockImplementation(options => ({ id: 'test-timing-middleware', ...options })) // piece of code hidden }) Jest - javascript Jest - javascript - Nuxtjs

Slide 22

Slide 22 text

test('should construct server', () => { const nuxt = createNuxt() // piece of code hidden let server = new Server(nuxt) expect(server.nuxt.hook).toBeCalledWith('close', expect.any(Function)) // piece of code hidden const closeHook = server.nuxt.hook.mock.calls[0][1] server.close = jest.fn() expect(server.close).not.toBeCalled() closeHook() expect(server.close).toBeCalledTimes(1) // piece of code hidden server = new Server(nuxt) expect(server.publicPath).toBe(nuxt.options.build._publicPath) }) Jest - javascript - Nuxtjs

Slide 23

Slide 23 text

test('should construct server', () => { const nuxt = createNuxt() // piece of code hidden let server = new Server(nuxt) expect(server.nuxt.hook).toBeCalledWith('close', expect.any(Function)) // piece of code hidden const closeHook = server.nuxt.hook.mock.calls[0][1] server.close = jest.fn() expect(server.close).not.toBeCalled() closeHook() expect(server.close).toBeCalledTimes(1) // piece of code hidden server = new Server(nuxt) expect(server.publicPath).toBe(nuxt.options.build._publicPath) }) Jest - javascript - Nuxtjs

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

const Wrapped = ( code, test, testCaseTests, sourceCodeTests, guideContent, whenDoneRedirectTo, waitCodeToBeExecutedOnStep, enableEditorOnStep, trackSection, testCaseStrategy, sourceCodeStrategy, disableEditor, introContent, enableIntroOnStep, editorOptions, attentionAnimationTo = [] ) => { } Jest - Javascript - Reactjs

Slide 27

Slide 27 text

const Wrapped = ( code, test, testCaseTests, sourceCodeTests, guideContent, whenDoneRedirectTo, waitCodeToBeExecutedOnStep, enableEditorOnStep, trackSection, testCaseStrategy, sourceCodeStrategy, disableEditor, introContent, enableIntroOnStep, editorOptions, attentionAnimationTo = [] ) => { } Jest - Javascript - Reactjs

Slide 28

Slide 28 text

test('should accept editor options by parameter', () => { const HoC = Rocket( null, null, null, null, null, null, null, 'my-section', null, null, null, null, { [SOURCE_CODE]: { readOnly: true }, [TEST_CODE]: {} } ); const wrapper = shallow(); expect(wrapper.instance().state.editorOptions[SOURCE_CODE].readOnly).toBe(true); expect(wrapper.find('EditorManager').props().options[SOURCE_CODE].readOnly).toEqual(true); }); Jest - Javascript - Reactjs

Slide 29

Slide 29 text

test('should accept editor options by parameter', () => { const HoC = Rocket( null, null, null, null, null, null, null, 'my-section', null, null, null, null, { [SOURCE_CODE]: { readOnly: true }, [TEST_CODE]: {} } ); const wrapper = shallow(); expect(wrapper.instance().state.editorOptions[SOURCE_CODE].readOnly).toBe(true); expect(wrapper.find('EditorManager').props().options[SOURCE_CODE].readOnly).toEqual(true); }); Jest - Javascript - Reactjs

Slide 30

Slide 30 text

test('should accept editor options by parameter', () => { const HoC = Rocket( null, null, null, null, null, null, null, 'my-section', null, null, null, null, { [SOURCE_CODE]: { readOnly: true }, [TEST_CODE]: {} } ); const wrapper = shallow(); expect(wrapper.instance().state.editorOptions[SOURCE_CODE].readOnly).toBe(true); expect(wrapper.find('EditorManager').props().options[SOURCE_CODE].readOnly).toEqual(true); }); Jest - Javascript - Reactjs

Slide 31

Slide 31 text

test('should accept editor options by parameter', () => { const HoC = Rocket( null, null, null, null, null, null, null, 'my-section', null, null, null, null, { [SOURCE_CODE]: { readOnly: true }, [TEST_CODE]: {} } ); const wrapper = shallow(); expect(wrapper.instance().state.editorOptions[SOURCE_CODE].readOnly).toBe(true); expect(wrapper.find('EditorManager').props().options[SOURCE_CODE].readOnly).toEqual(true); }); Jest - Javascript - Reactjs

Slide 32

Slide 32 text

The automation server

Slide 33

Slide 33 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java - Jenkins

Slide 34

Slide 34 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java Junit - Java - Jenkins

Slide 35

Slide 35 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java Junit - Java - Jenkins

Slide 36

Slide 36 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java Junit - Java - Jenkins

Slide 37

Slide 37 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java Junit - Java - Jenkins

Slide 38

Slide 38 text

/** * Makes sure the use of "localhost" in the Hudson URL reports a warning. */ @Test public void localhostWarning() throws Exception { HtmlPage p = j.createWebClient().goTo("configure"); HtmlInput url = p.getFormByName("config").getInputByName("_.url"); url.setValueAttribute("http://localhost:1234/"); assertThat( p.getDocumentElement().getTextContent(), containsString("instead of localhost") ); } Junit - Java Junit - Java - Jenkins

Slide 39

Slide 39 text

● Adding tests after the source code ● Lack of SOLID principles ● Object Calisthenics? Root cause

Slide 40

Slide 40 text

3. The liar - 🏆4 An entire unit test that passes all of the test cases it has and appears valid, but upon closer inspection it is discovered that it doesn’t really test the intended target at all. Crafting code

Slide 41

Slide 41 text

test('the data is peanut butter', () => { function callback(data) { expect(data).toBe('peanut butter'); } fetchData(callback); }); Jest - javascript

Slide 42

Slide 42 text

test('the data is peanut butter', () => { function callback(data) { expect(data).toBe('peanut butter'); } fetchData(callback); }); Jest - javascript

Slide 43

Slide 43 text

test('the data is peanut butter', () => { function callback(data) { expect(data).toBe('peanut butter'); } fetchData(callback); }); Jest - javascript

Slide 44

Slide 44 text

test('the data is peanut butter', done => { function callback(data) { try { expect(data).toBe('peanut butter'); done(); } catch (error) { done(error); } } fetchData(callback); }); Jest - javascript

Slide 45

Slide 45 text

test('the data is peanut butter', done => { function callback(data) { try { expect(data).toBe('peanut butter'); done(); } catch (error) { done(error); } } fetchData(callback); }); Jest - javascript

Slide 46

Slide 46 text

test('the data is peanut butter', done => { function callback(data) { try { expect(data).toBe('peanut butter'); done(); } catch (error) { done(error); } } fetchData(callback); }); Jest - javascript

Slide 47

Slide 47 text

test('the data is peanut butter', done => { function callback(data) { try { expect(data).toBe('peanut butter'); done(); } catch (error) { done(error); } } fetchData(callback); }); Jest - javascript

Slide 48

Slide 48 text

test('the data is peanut butter', done => { function callback(data) { try { expect(data).toBe('peanut butter'); done(); } catch (error) { done(error); } } fetchData(callback); }); Jest - javascript

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

@Test fun `update user`() { val userId = 999 service.updateUserCustomAttributes( userId, mapOf(UserCustomAttribute.JOB to "MANAGER") ) } @Test fun `delete user`() { val userId = UserId.fromUuidString("e080-c8a-41bb-8ef-415124637e99") service.deleteUser(userId) } Junit - kotlin

Slide 51

Slide 51 text

@Test fun `update user`() { val userId = 999 service.updateUserCustomAttributes( userId, mapOf(UserCustomAttribute.JOB to "MANAGER") ) } @Test fun `delete user`() { val userId = UserId.fromUuidString("e080-c8a-41bb-8ef-415124637e99") service.deleteUser(userId) } Junit - kotlin

Slide 52

Slide 52 text

@Test fun `update user`() { val userId = 999 service.updateUserCustomAttributes( userId, mapOf(UserCustomAttribute.JOB to "MANAGER") ) } @Test fun `delete user`() { val userId = UserId.fromUuidString("e080-c8a-41bb-8ef-415124637e99") service.deleteUser(userId) } Junit - kotlin

Slide 53

Slide 53 text

● Wow, async - watch out! ● Test without assertions Points of attention

Slide 54

Slide 54 text

● Lack of practice on TDD ● Oriented to coverage Root cause

Slide 55

Slide 55 text

4. The giant - 🏆5 A unit test that, although it is validly testing the object under test, can span thousands of lines and contain many many test cases. This can be an indicator that the system under tests is a God Object. Crafting code

Slide 56

Slide 56 text

namespace PhpOffice\PhpWord\Shared; class ConverterTest extends \PHPUnit\Framework\TestCase { public function testUnitConversions() { $values = array(); $values[] = 0; // zero value $values[] = rand(1, 100) / 100; // fraction number $values[] = rand(1, 100); // integer foreach ($values as $value) { $result = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); PHPUnit - PHPOffice/Word

Slide 57

Slide 57 text

namespace PhpOffice\PhpWord\Shared; class ConverterTest extends \PHPUnit\Framework\TestCase { public function testUnitConversions() { $values = array(); $values[] = 0; // zero value $values[] = rand(1, 100) / 100; // fraction number $values[] = rand(1, 100); // integer foreach ($values as $value) { $result = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); PHPUnit - PHPOffice/Word

Slide 58

Slide 58 text

namespace PhpOffice\PhpWord\Shared; class ConverterTest extends \PHPUnit\Framework\TestCase { public function testUnitConversions() { $values = array(); $values[] = 0; // zero value $values[] = rand(1, 100) / 100; // fraction number $values[] = rand(1, 100); // integer foreach ($values as $value) { $result = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); PHPUnit - PHPOffice/Word

Slide 59

Slide 59 text

namespace PhpOffice\PhpWord\Shared; class ConverterTest extends \PHPUnit\Framework\TestCase { public function testUnitConversions() { $values = array(); $values[] = 0; // zero value $values[] = rand(1, 100) / 100; // fraction number $values[] = rand(1, 100); // integer foreach ($values as $value) { $result = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); PHPUnit - PHPOffice/Word

Slide 60

Slide 60 text

namespace PhpOffice\PhpWord\Shared; class ConverterTest extends \PHPUnit\Framework\TestCase { public function testUnitConversions() { $values = array(); $values[] = 0; // zero value $values[] = rand(1, 100) / 100; // fraction number $values[] = rand(1, 100); // integer foreach ($values as $value) { $result = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); PHPUnit - PHPOffice/Word

Slide 61

Slide 61 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 62

Slide 62 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 63

Slide 63 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 64

Slide 64 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 65

Slide 65 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 66

Slide 66 text

$result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); PHPUnit - PHPOffice/Word

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 69

Slide 69 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 70

Slide 70 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 71

Slide 71 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 72

Slide 72 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 73

Slide 73 text

$result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); PHPUnit - PHPOffice/Word

Slide 74

Slide 74 text

$result = Converter::degreeToAngle($value); $this->assertEquals((int) round($value * 60000), $result); $result = Converter::angleToDegree($value); $this->assertEquals(round($value / 60000), $result); } } PHPUnit - PHPOffice/Word

Slide 75

Slide 75 text

$result = Converter::degreeToAngle($value); $this->assertEquals((int) round($value * 60000), $result); $result = Converter::angleToDegree($value); $this->assertEquals(round($value / 60000), $result); } } PHPUnit - PHPOffice/Word

Slide 76

Slide 76 text

● How many test cases do I have? ● Lacks feedback from the test ● Data provider / Parameterized tests Points of attention

Slide 77

Slide 77 text

● Test after, instead of test first Root cause

Slide 78

Slide 78 text

5. The slow poke - 🏆6 A unit test that runs incredibly slow. When developers kick it off, they have time to go to the bathroom, grab a smoke, or worse, kick the test off before they go home at the end of the day. Crafting code

Slide 79

Slide 79 text

Slow poke?

Slide 80

Slide 80 text

Asynchronous Behavior Eradicating Non-Determinism in Tests Martin Fowler, 2011

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

test('should show Buggy on user interaction by keyboard', done => { const wrapper = mount( ); setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); Jest - Javascript - Reactjs

Slide 84

Slide 84 text

test('should show Buggy on user interaction by keyboard', done => { const wrapper = mount( ); setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); Jest - Javascript - Reactjs

Slide 85

Slide 85 text

setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(0); done(); }, 500); }); Jest - Javascript - Reactjs

Slide 86

Slide 86 text

setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(0); done(); }, 500); }); Jest - Javascript - Reactjs

Slide 87

Slide 87 text

setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(0); done(); }, 500); }); Jest - Javascript - Reactjs

Slide 88

Slide 88 text

setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(0); done(); }, 500); }); Jest - Javascript - Reactjs

Slide 89

Slide 89 text

setTimeout(() => { wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(1); const keypress = new KeyboardEvent('keydown', {keyCode: 37}); document.dispatchEvent(keypress); wrapper.update(); expect(wrapper.find('BuggySleepy').length).toBe(0); done(); }, 500); }); Jest - Javascript - Reactjs

Slide 90

Slide 90 text

● CRON jobs ● Leap year / any time related ● Lack of control over non-determinism Points of attention

Slide 91

Slide 91 text

Focus more on integration test instead of unit, this can lead to slow suites. This also can happen when focusing too much on coverage instead of having it as a side effect. Points of attention

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Trying to reverse engineer the TDD flow. It often happens when there is no tests on the code and as soon as developers start to add them, it goes back to integration test and coverage. Points of attention

Slide 94

Slide 94 text

Ice cream cone Testing is Good. Pyramids are Bad. Ice Cream Cones are the Worst - Stephen H Fishman

Slide 95

Slide 95 text

Pyramid Testing is Good. Pyramids are Bad. Ice Cream Cones are the Worst - Stephen H Fishman

Slide 96

Slide 96 text

Crafting code Testing is Good. Pyramids are Bad. Ice Cream Cones are the Worst - Stephen H Fishman

Slide 97

Slide 97 text

6. Wrapping up We are almost done! Crafting code

Slide 98

Slide 98 text

● The liar ● Excessive setup ● The giant ● The slow poke ● and many more! What we covered

Slide 99

Slide 99 text

Most of the anti-patterns presented are related to test last Test last

Slide 100

Slide 100 text

If it's hard to test, take a step back. Hard to test

Slide 101

Slide 101 text

Working skeleton Growing object oriented software, guided by tests Steve Freeman and Nat Pryce Crafting code

Slide 102

Slide 102 text

https://www.codurance.com/publications/building-testing-culture

Slide 103

Slide 103 text

Matheus Marabesi Hello there, you can call me Marabesi, But my name is Matheus Marabesi, I work at Codurance as a Software craftsperson. I enjoy talking about anything related to: testing, patterns and gamification. You can find me at @MatheusMarabesi or https://marabesi.com Codurance Crafting Code