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

Testing Rails Service Oriented Architecture

Testing Rails Service Oriented Architecture

Travis Douce

August 29, 2014
Tweet

More Decks by Travis Douce

Other Decks in Programming

Transcript

  1. What are Monolithic Applications? What is SOA? Testing Monolithic Applications

    Testing SOA Challenges with Testing SOA Strategies for Testing SOA
  2. What are Monolithic Applications? What is SOA? Testing Monolithic Applications

    Testing SOA Challenges with Testing SOA Strategies for Testing SOA Develop Features for SOA application
  3. This is why writing tests for SOA is hard especially

    for applications like Web Client
  4. No tests Stub HTTP requests from Web Client to School

    API Make HTTP requests from Web Client to School API and seed School API test database ! ! Other ? Strategies
  5. No tests Stub HTTP requests from Web Client to School

    API Make HTTP requests from Web Client to School API and seed School API test database Create/destroy data using School API’s API ! Other ? Strategies
  6. / \ /~- y Y V ,-^-./ | \,-^-. /

    { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ /\ ~\ / \ Y V | \,-^-. | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () / / \ /~-~\ / y Y V ,-^-./ | \,-^- / { | } \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ \/ \/ \ \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \ { \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y ,-^ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V -^-./ | \,-^-. { | } \ \ | / A /\ \/ \ \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^ / { | } \ | /\ A / \ / /\ ~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ \ / .\-/. /\ () () /\ / \ /~-~\ / \ y Y V ,-^-./ | \,-^-. / { | } \ \ | / /\ A /\ / \/ \/ \ / \ My experience with SOA
  7. Web Client Dev: Finished the feature. Tests are green. School

    API Dev: Great! Web Client Dev: I deployed. I also told the customer.
  8. Web Client Dev: Finished the feature. Tests are green. School

    API Dev: Great! Web Client Dev: I deployed. I also told the customer. Customer:
  9. Web Client Dev: Finished the feature. Tests are green. School

    API Dev: Great! Web Client Dev: I deployed. I also told the customer. Customer: The site is down :/
  10. School API Dev: I renamed /pupils to /students School API

    Dev: Web Client Dev: What!? My tests were green.
  11. School API Dev: I renamed /pupils to /students School API

    Dev: Ooops. I forgot to tell you :( Web Client Dev: What!? My tests were green.
  12. School API Dev: I renamed /pupils to /students Web Client

    Dev: School API Dev: Ooops. I forgot to tell you :( Web Client Dev: What!? My tests were green.
  13. School API Dev: I renamed /pupils to /students Web Client

    Dev: ¯\_(π)_/¯ School API Dev: Ooops. I forgot to tell you :( Web Client Dev: What!? My tests were green.
  14. School API Dev: It won’t happen again. Promise <3 Web

    Client Dev: Tell me when you make changes, please :)
  15. Web Client dev no longer trusts the Web Client’s test

    suite. Problem with previous strategy:
  16. Solution: Make HTTP requests to School API when runnig Web

    Client’s test suite Web Client dev no longer trusts the Web Client’s test suite. Problem with previous strategy:
  17. Strategy #2 Make HTTP requests and seed School API database

    Start School API server in test env Seed School API test database
  18. Start School API server in test env Web Client issues

    HTTP requests to School API Seed School API test database Strategy #2 Make HTTP requests and seed School API database
  19. 1 test Schools 1 Principals s 1 Students 0 School

    API Web Client 1 passing After
  20. Manage School API server Confidence X Seed School API db

    AND issue HTTP requests Strategy #2
  21. Manage School API server Bleed state between tests Confidence X

    Seed School API db AND issue HTTP requests Strategy #2
  22. Problem with previous strategy Solution Create the test data needed

    for each test Frequently updating seed data for School API test database when each test is run
  23. Create test data using School API’s API Strategy #3 Start

    School API server in test env Web Client issues HTTP requests to School API
  24. Customer: Web Client Dev: You there? Yep, need something? Customer:

    I forgot to mention, you can NOT create a school through School API public API.
  25. Manage School API server Not possible ! Confidence X Strategy

    #3 Create test data using School API’s API
  26. Manage School API server Not possible Creating complex data associations

    ! Confidence X Strategy #3 Create test data using School API’s API
  27. Manage School API server Not possible Creating complex data associations

    Bleed state between tests Confidence X Strategy #3 Create test data using School API’s API
  28. Problem with previous strategy Solution Create a school, but with

    School API’s API Can not create school with School API’s API
  29. I want to create test data in School API test

    database with factory_girl from the Web Client
  30. remote_factory_girl Strategy #4 Start School API server in test env

    Install remote_factory_girl_home_rails in School API Install remote_factory_girl in Web Client
  31. remote_factory_girl Strategy #4 Start School API server in test env

    Web Client issues HTTP requests to School API Install remote_factory_girl_home_rails in School API Install remote_factory_girl in Web Client
  32. Customer: You there? Yep, need something? Customer: Student emails have

    to be UNIQUE. School API Dev: School API Dev:
  33. Customer: You there? Yep, need something? Customer: Student emails have

    to be UNIQUE. School API Dev: Ok. Not a problem. School API Dev:
  34. #4 FAILS! Schools 3 Principals s 3 Students 1 School

    API test db student email has to be unique
  35. Manage School API server ! Confidence Create complex test data

    Create data not available through API X remote_factory_girl Strategy #4
  36. Manage School API server Bleed state between tests Confidence Create

    complex test data Create data not available through API X remote_factory_girl Strategy #4
  37. Problem with previous strategy Solution Destroy test data after each

    test with remote_database_cleaner State in School API test database persists between tests in Web Client
  38. remote_database_cleanear Strategy #5 Start School API server in test env

    Install remote_database_cleaner_home_rails in School API Install remote_database_cleaner in Web Client
  39. remote_database_cleanear Strategy #5 Start School API server in test env

    Install remote_database_cleaner_home_rails in School API Install remote_database_cleaner in Web Client Web Client issues HTTP requests to School API
  40. Manage School API server ! Does not bleed state between

    tests ! X remote_database_cleaner Strategy #4
  41. The Takeaway Integration tests give us more confidence in SOA

    Requires more setup initially But, pays dividends in the long run
  42. What are Monolithic Applications? What is SOA? Testing Monolithic Applications

    Testing SOA Challenges with Testing SOA Strategies for Testing SOA
  43. What are Monolithic Applications? What is SOA? Testing Monolithic Applications

    Testing SOA Challenges with Testing SOA Strategies for Testing SOA Develop Features for SOA application