Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDD anti patterns - episode 5 - with Sofia Carballo and Juan Pablo

TDD anti patterns - episode 5 - with Sofia Carballo and Juan Pablo

Testing practices has increasing its adoption by developers, shifting left the test responsibilities

And increasing the quality of the code, besides that, continuous testing is an agile practice that impacts the software development life cycle. In this talk we are going to focus on the following TDD anti-patterns: The stranger, The operating system evangelist, Success against all odds and The free ride.

Marabesi

April 21, 2022
Tweet

More Decks by Marabesi

Other Decks in Programming

Transcript

  1. TDD - EP 5
    codurance.com
    Testing anti-patterns - The stranger, The
    operating system evangelist, Success
    against all odds and The free ride

    View full-size slide

  2. 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

    View full-size slide

  3. 1. Intro - Recap
    2. The stranger
    3. The operating system evangelist
    4. Success against all odds
    5. The free ride
    6. Wrapping up
    Crafting code
    Agenda

    View full-size slide

  4. 1. Recap
    Episode 1, Episode 2, Episode 3,
    Episode 4
    Getting started

    View full-size slide

  5. 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

    View full-size slide

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

    View full-size slide

  7. Anti patterns - Survey takeaways
    1. Survey notes: Javascript, PHP and Java were the most used programming languages
    2. Survey notes: Practitioners usually informally learn TDD
    3. The anti patterns covered were related to test last
    4. Subjects we touched around testability: SOLID, Object calisthenics, Non-determinism and the
    test pyramid
    5. Examples are from open source projects and also extraction from real code bases

    View full-size slide

  8. MOST POPULAR

    View full-size slide

  9. 2. Anti-patterns - Episode 5
    The stranger, The operating system
    evangelist, Success against all odds and
    The free ride
    Getting started

    View full-size slide

  10. 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

    View full-size slide

  11. 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 7
    The Operating System Evangelist 8
    Success Against All Odds 3
    The Free Ride 8
    The One
    The Peeping Tom
    The Slow Poke
    James Carr - TDD Anti-Patterns

    View full-size slide

  12. 2. The stranger - 🏆 7
    Crafting code

    View full-size slide

  13. 2. The stranger - 🏆 7
    A test case that doesn’t even belong in the unit
    test it is part of. it’s really testing a separate
    object, most likely an object that is used by the
    object under test, but the test case has gone and
    tested that object directly without relying on the
    output from the object under test making use of
    that object for its own behavior.
    Crafting code

    View full-size slide

  14. Usually the strange is not
    something easy to spot

    View full-size slide

  15. ● It depends on context
    The stranger

    View full-size slide

  16. ● It depends on context
    ● It is related to the xUnit pattern in the section "Test smells"
    The stranger

    View full-size slide

  17. ● It depends on context
    ● It is related to the xUnit pattern in the section "Test smells"
    ● It can be related to mocks
    The stranger

    View full-size slide

  18. 3. The Operating System Evangelist - 🏆8
    Crafting code

    View full-size slide

  19. 3. The Operating System Evangelist - 🏆8
    A unit test that relies on a specific operation
    system environment to be in place in order to
    work.
    Crafting code

    View full-size slide

  20. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  21. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  22. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  23. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  24. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  25. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  26. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  27. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  28. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  29. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  30. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  31. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  32. class LutrisWrapperTestCase(unittest.TestCase):
    def test_excluded_initial_process(self):
    "Test that an excluded process that starts a monitored process works"
    env = os.environ.copy()
    env['PYTHONPATH'] = ':'.join(sys.path)
    # run the lutris-wrapper with a bash subshell. bash is "excluded"
    wrapper_proc = subprocess.Popen(
    [
    sys.executable, lutris_wrapper_bin, 'title', '0', '1', 'bash', 'bash',
    '-c',
    "echo Hello World; exec 1>&-; while sleep infinity; do true; done"
    ],
    stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env,
    )
    Python - Lutris

    View full-size slide

  33. Go lang - Windows portability

    View full-size slide

  34. Go lang - Windows portability

    View full-size slide

  35. @Test
    public void testWithoutSOptionAndWithoutJENKINS_URL() throws Exception {
    Assume.assumeThat(System.getenv("JENKINS_URL"), is(nullValue()));
    // TODO instead remove it from the process env?
    assertNotEquals(0, launch("java",
    "-Duser.home=" + home,
    "-jar", jar.getAbsolutePath(),
    "who-am-i")
    );
    }
    Java - Jenkins

    View full-size slide

  36. @Test
    public void testWithoutSOptionAndWithoutJENKINS_URL() throws Exception {
    Assume.assumeThat(System.getenv("JENKINS_URL"), is(nullValue()));
    // TODO instead remove it from the process env?
    assertNotEquals(0, launch("java",
    "-Duser.home=" + home,
    "-jar", jar.getAbsolutePath(),
    "who-am-i")
    );
    }
    Java - Jenkins

    View full-size slide

  37. FLASH BACK
    Episode 2 - The local hero
    Episode 2 - The local hero

    View full-size slide

  38. https://www.codurance.com/publications/tdd-anti-patterns-chapter-2

    View full-size slide

  39. 4. Success Against All Odds - 🏆3
    Crafting code

    View full-size slide

  40. 4. Success Against All Odds - 🏆3
    A test that was written pass first rather than
    fail first. As an unfortunate side effect, the
    test case happens to always pass even
    though the test should fail.
    Crafting code

    View full-size slide

  41. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  42. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  43. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  44. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  45. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  46. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  47. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  48. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  49. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  50. @Repository
    class ProductsRepositoryWithPostgres(
    private val entityManager: EntityManager
    ) : Repository {
    override fun listFilteredProducts(query: String?, input: PagingQueryInput?) {
    val pageRequest: PageRequest = input.asPageRequest()
    val page: Page = if (query.isNullOrBlank()) {
    entityManager.findAll(pageRequest)
    } else {
    entityManager.findAllByName(query, pageRequest)
    }
    return page
    }
    }
    mockk - kotlin

    View full-size slide

  51. private fun setupBeforeAll() {
    productIds = (1..100).map { db().productWithDependencies().apply().get() }
    productIdsContainingWood.addAll(
    (1..3).map { insertProductWithName("WoodyWoodOrange " + faker.funnyName().name()) }
    )
    productIdsContainingWood.addAll(
    (1..3).map {
    insertProductWithName(
    faker.funnyName().name() + " WoodyWoodOrange " + faker.funnyName().name()
    )
    }
    )
    mockk - kotlin

    View full-size slide

  52. private fun setupBeforeAll() {
    productIds = (1..100).map { db().productWithDependencies().apply().get() }
    productIdsContainingWood.addAll(
    (1..3).map { insertProductWithName("WoodyWoodOrange " + faker.funnyName().name()) }
    )
    productIdsContainingWood.addAll(
    (1..3).map {
    insertProductWithName(
    faker.funnyName().name() + " WoodyWoodOrange " + faker.funnyName().name()
    )
    }
    )
    mockk - kotlin

    View full-size slide

  53. private fun setupBeforeAll() {
    productIds = (1..100).map { db().productWithDependencies().apply().get() }
    productIdsContainingWood.addAll(
    (1..3).map { insertProductWithName("WoodyWoodOrange " + faker.funnyName().name()) }
    )
    productIdsContainingWood.addAll(
    (1..3).map {
    insertProductWithName(
    faker.funnyName().name() + " WoodyWoodOrange " + faker.funnyName().name()
    )
    }
    )
    mockk - kotlin

    View full-size slide

  54. private fun setupBeforeAll() {
    productIds = (1..100).map { db().productWithDependencies().apply().get() }
    productIdsContainingWood.addAll(
    (1..3).map { insertProductWithName("WoodyWoodOrange " + faker.funnyName().name()) }
    )
    productIdsContainingWood.addAll(
    (1..3).map {
    insertProductWithName(
    faker.funnyName().name() + " WoodyWoodOrange " + faker.funnyName().name()
    )
    }
    )
    mockk - kotlin

    View full-size slide

  55. private fun setupBeforeAll() {
    productIds = (1..100).map { db().productWithDependencies().apply().get() }
    productIdsContainingWood.addAll(
    (1..3).map { insertProductWithName("WoodyWoodOrange " + faker.funnyName().name()) }
    )
    productIdsContainingWood.addAll(
    (1..3).map {
    insertProductWithName(
    faker.funnyName().name() + " WoodyWoodOrange " + faker.funnyName().name()
    )
    }
    )
    mockk - kotlin

    View full-size slide

  56. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  57. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  58. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  59. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  60. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  61. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  62. productIdsContainingWood.addAll(
    (1..2).map { insertProductWithName(faker.funnyName().name() + " WoodyWoodOrange") }
    )
    cancelledProductId =
    db().productWithDependencies("status" to Product.CANCELLED).apply().get()
    idsOfStartedByWithCustomerDeadline.addAll(
    listOf(
    db().productWithDependencies("customer_deadline" to "2022-04-03T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-02T00:00:00.00Z").apply()
    .get(),
    db().productWithDependencies("customer_deadline" to "2022-04-01T00:00:00.00Z").apply()
    .get(),
    )
    )
    }
    mockk - kotlin

    View full-size slide

  63. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  64. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  65. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  66. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  67. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  68. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  69. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  70. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  71. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  72. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  73. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  74. @Test
    fun `list products sorted by creation at date descending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_DESC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  75. ● Sorting
    ● Pagination
    Points of attention
    WHAT COULD WE DO?

    View full-size slide

  76. Focus on a single thing
    SORTING

    View full-size slide

  77. @Test
    fun `list products sorted by creation at date ascending`() {
    val pageQueryInput = PagingQueryInput(
    size = 30, page = 0, sort = listOf(Sort.CREATED_AT_ASC)
    )
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(4)
    assertThat(result.totalElements).isEqualTo(112)
    assertThat(result.content.size).isEqualTo(30)
    assertThat(result.content).allSatisfy { productIds.subList(0, 29).contains(it.id) }
    }
    mockk - kotlin

    View full-size slide

  78. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  79. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  80. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  81. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  82. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  83. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  84. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  85. @Test
    fun `list products sorted by ascending creation date`() {
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_ASC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  86. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  87. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  88. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  89. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  90. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  91. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  92. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  93. @Test
    fun `list products sorted by creation at date descending`() {
    db().productWithDependencies("created_at" to "2022-04-01T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-02T00:00:00.00Z").apply()
    db().productWithDependencies("created_at" to "2022-04-03T00:00:00.00Z").apply()
    val pageQueryInput = PagingQueryInput(sort = listOf(SortOrder.CREATED_AT_DESC))
    val result = repository.listFilteredProducts("", pageQueryInput)
    assertThat(result.content[0].createdAt).isEqualTo("2022-04-03T00:00:00.00Z")
    assertThat(result.content[1].createdAt).isEqualTo("2022-04-02T00:00:00.00Z")
    assertThat(result.content[2].createdAt).isEqualTo("2022-04-01T00:00:00.00Z")
    }
    mockk - kotlin

    View full-size slide

  94. Focus on a single thing
    PAGINATION

    View full-size slide

  95. @Test
    fun `should list products`() {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProductBriefs(null, null, page)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  96. @Test
    fun `should list products`() {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProductBriefs(null, null, page)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  97. @Test
    fun `should list products`() {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProductBriefs(null, null, page)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  98. @Test
    fun `should list products`() {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProductBriefs(null, null, page)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  99. @Test
    fun `should list products`() {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProductBriefs(null, null, page)
    assertThat(result.currentPage).isEqualTo(0)
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  100. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  101. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  102. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  103. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  104. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  105. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin

    View full-size slide

  106. mockk - kotlin
    @Test
    fun `should be on the first page by default`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.currentPage).isEqualTo(0)
    }

    View full-size slide

  107. mockk - kotlin
    @Test
    fun `should be on the first page by default`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.currentPage).isEqualTo(0)
    }

    View full-size slide

  108. mockk - kotlin
    @Test
    fun `should be on the first page by default`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.currentPage).isEqualTo(0)
    }

    View full-size slide

  109. mockk - kotlin
    @Test
    fun `should be on the first page by default`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.currentPage).isEqualTo(0)
    }

    View full-size slide

  110. @Test
    fun `should have one page when the list is ten`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.totalPages).isEqualTo(1)
    }
    mockk - kotlin
    @Test
    fun `should be on the first page by default`()
    {
    insertTenProducts()
    val page = PagingQueryInput(size = 10)
    val result = repository.listFilteredProducts(
    null,
    null,
    Page
    )
    assertThat(result.currentPage).isEqualTo(0)
    }

    View full-size slide

  111. 5. The Free Ride - 🏆8
    Crafting code

    View full-size slide

  112. describe('Request.headers', function () {
    it('should work', async () => {
    const { page, server, isChrome } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    if (isChrome)
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    else
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    describe('Request.headers', function () {
    itChromeOnly('should define Chrome as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    });
    itFirefoxOnly('should define Firefox as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    Puppeteer
    A

    View full-size slide

  113. describe('Request.headers', function () {
    it('should work', async () => {
    const { page, server, isChrome } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    if (isChrome)
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    else
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    describe('Request.headers', function () {
    itChromeOnly('should define Chrome as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    });
    itFirefoxOnly('should define Firefox as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    Puppeteer
    B

    View full-size slide

  114. describe('Request.headers', function () {
    it('should work', async () => {
    const { page, server, isChrome } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    if (isChrome)
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    else
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    describe('Request.headers', function () {
    itChromeOnly('should define Chrome as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    });
    itFirefoxOnly('should define Firefox as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    Puppeteer
    A
    B

    View full-size slide

  115. describe('Request.headers', function () {
    it('should work', async () => {
    const { page, server, isChrome } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    if (isChrome)
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    else
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    describe('Request.headers', function () {
    itChromeOnly('should define Chrome as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    });
    itFirefoxOnly('should define Firefox as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    Puppeteer
    A
    B
    Could you spot something that seems to be a smell?

    View full-size slide

  116. describe('Request.headers', function () {
    it('should work', async () => {
    const { page, server, isChrome } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    if (isChrome)
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    else
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    describe('Request.headers', function () {
    itChromeOnly('should define Chrome as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Chrome');
    });
    itFirefoxOnly('should define Firefox as user agent header', async () => {
    const { page, server } = getTestState();
    const response = await page.goto(server.EMPTY_PAGE);
    expect(response.request().headers()['user-agent']).toContain('Firefox');
    });
    });
    Puppeteer
    A
    B
    What about anti-patterns?

    View full-size slide

  117. 5. The Free Ride - 🏆8
    Rather than write a new test case method to
    test another feature or functionality, a new
    assertion rides along in an existing test case.
    Crafting code

    View full-size slide

  118. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  119. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  120. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  121. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  122. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  123. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  124. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  125. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  126. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  127. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  128. it('Page.Events.RequestFailed', async () => {
    const { page, server, isChrome } = getTestState();
    await page.setRequestInterception(true);
    page.on('request', (request) => {
    if (request.url().endsWith('css')) request.abort();
    else request.continue();
    });
    const failedRequests = [];
    page.on('requestfailed', (request) => failedRequests.push(request));
    await page.goto(server.PREFIX + '/one-style.html');
    expect(failedRequests.length).toBe(1);
    expect(failedRequests[0].url()).toContain('one-style.css');
    expect(failedRequests[0].response()).toBe(null);
    expect(failedRequests[0].resourceType()).toBe('stylesheet');
    if (isChrome)
    expect(failedRequests[0].failure().errorText).toBe('net::ERR_FAILED');
    else
    expect(failedRequests[0].failure().errorText).toBe('NS_ERROR_FAILURE');
    expect(failedRequests[0].frame()).toBeTruthy();
    });
    Javascript/Typescript - Puppeteer

    View full-size slide

  129. public class ToolLocationTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void toolCompatibility() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    Java - Jenkins

    View full-size slide

  130. public class ToolLocationTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void toolCompatibility() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    Java - Jenkins

    View full-size slide

  131. public class ToolLocationTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void toolCompatibility() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    Java - Jenkins

    View full-size slide

  132. public class ToolLocationTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void toolCompatibility() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    Java - Jenkins

    View full-size slide

  133. public class ToolLocationTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void toolCompatibility() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    Java - Jenkins

    View full-size slide

  134. The automation server

    View full-size slide

  135. public class ToolLocationTest {
    @Test
    @LocalData
    public void shouldBeCompatibleWithMaven() {
    Maven.MavenInstallation[] maven = j.jenkins.getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
    assertEquals(1, maven.length);
    assertEquals("bar", maven[0].getHome());
    assertEquals("Maven 1", maven[0].getName());
    }
    @Test
    @LocalData
    public void shouldBeCompatibleWithAnt() {
    Ant.AntInstallation[] ant = j.jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations();
    assertEquals(1, ant.length);
    assertEquals("foo", ant[0].getHome());
    assertEquals("Ant 1", ant[0].getName());
    }
    @Test
    @LocalData
    Java - Jenkins

    View full-size slide

  136. @Test
    @LocalData
    public void shouldBeCompatibleWithJdk() {
    JDK[] jdk = j.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getInstallations();
    assertEquals(Arrays.asList(jdk), j.jenkins.getJDKs());
    assertEquals(2, jdk.length); // JenkinsRule adds a 'default' JDK
    assertEquals("default", jdk[1].getName()); // make sure it's really that we're seeing
    assertEquals("FOOBAR", jdk[0].getHome());
    assertEquals("FOOBAR", jdk[0].getJavaHome());
    assertEquals("1.6", jdk[0].getName());
    }
    }
    Java - Jenkins

    View full-size slide

  137. 6. Wrapping up
    We are almost done!
    Crafting code

    View full-size slide

  138. ● The stranger
    ● The operating system evangelist
    ● Success against all odds
    ● The free ride
    ● and two more left!
    What we covered

    View full-size slide

  139. https://www.codurance.com/publications/building-testing-culture
    https://www.codurance.com/publications/tdd-anti-patterns-chapter-1

    View full-size slide

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

    View full-size slide

  141. https://www.codurance.com/events

    View full-size slide

  142. 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

    View full-size slide