Business test data for automated tests



  • My automated tests (at the GUI/API levels) require to have already existing test data - like users or privileges assigned to them. I want them to be stable and able to run independently every time so I cannot hardcode this data. Also, I wouldn't like to create them as a part of test as it could make my tests more brittle.

    Lets assume that a system is a basic CRUD for books management. I'd like to automate test case like "modify book name". In order to do this, first I need to have already created book and user with privilege to modify it. Similar situation occurs for most of other test cases.

    Should I prepare this test data before tests, e.g. using API interface? Or maybe I should mock it somehow?



  • I would suggest:

    1. Create all the users and books you need in-suite setup.
    2. Drive your test through data-driven through CSV or JSON
    3. Delete the configuration in suite-tear down

    in CSV put in all the details like:

    user,privilege, action, resource, expected output

    a sample CSV would be:

    user,privileg, action, resource, expected output
    test1,admin, delete, v1/book/1,successfly deleted
    test1,basic, delete, v1/book/1,you don't have enough privillege
    test1,basic, get, v1/book/1, Have a nice reading time
    

    In this case, your test is driven through CSV you don't have to do anything in test because privilege, expected message, character everything is defined in CSV itself.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2