I have been working on REST API test automation in JAVA and have many approaches in my mind but not able to decide which one is better. Here are few approaches that I can think of-
Very Simple and straight approach where the testing team uses the same code repo on which dev is working, And we add the API test cases just like the unit test case in Test package of the same repo. PROS: less work because the testing team need not create DTOs etc., test cases will be available to the dev team, CONS: every time we add new test cases, we will have to do a pull request to merge the test cases, test cases will require immediate attention in case of dev code change otherwise there would be compilation failure.
Using a separate project with the third-party library, for example, REST ASSURED to automate the APIs testing. Here the testing team will import the dev code and use the DTOs, database access objects from the imported dev code. PROS: less work because the testing team need not create DTOs etc. CONS: test cases will require immediate attention in case of dev code change otherwise test cases will give compilation failure.
Do not use Dev code at all and write all DTOs and everything and automate the test cases using REST Assured in a separate project. PROS: Not any dependency on DEV code. CONS: The testing team will have to create lots of DTOs for mapping the request and response JSON. This will take too much efforts and time and will be a replication of task which is already done by the dev team.
Do not create DTOs and use JSON Schema to create DTOs at runtime and use REST ASSURED in a separate project. PROS: No need to create too many DTOs.Test case management and maintenance would be easy. CONS: Not found yet, please suggest what cons could be of this approach.
Or Any other approach which is better than the above approaches. Kindly suggest.