Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mock Tests to assist with developing REST API's locally. #1311

Closed
Tracked by #93
UmenR opened this issue Jun 8, 2021 · 9 comments
Closed
Tracked by #93

Add Mock Tests to assist with developing REST API's locally. #1311

UmenR opened this issue Jun 8, 2021 · 9 comments
Labels
wontfix This will not be worked on

Comments

@UmenR
Copy link
Member

UmenR commented Jun 8, 2021

Currently, all unit tests are written in a way that the test environment REST API's need to be available for them to pass. Instead, we need to improve the tests so that they are not dependent on using the test environment REST API's. Eg: using mocks.

@UmenR UmenR self-assigned this Jun 8, 2021
@nya-elimu
Copy link
Member

Relates to #1297

@nya-elimu
Copy link
Member

Relates to #1026

@nya-elimu
Copy link
Member

Currently, all unit tests are written in a way that the test environment REST API's need to be available for them to pass. Instead, we need to improve the tests so that they are not dependent on using the test environment REST API's. Eg: using mocks.

@UmenR Actually, the unit tests under ai.elimu.rest are not included when you run the tests locally with mvn test. This is because they are excluded in https://github.com/elimu-ai/webapp/blob/master/pom.xml#L154

So even if a developer's computer is offline (or the test server is down), the unit tests will pass when running mvn test.

@UmenR UmenR changed the title Improve Test Cases. Add Mock Tests to assist with developing REST API's locally. Jun 21, 2021
@UmenR
Copy link
Member Author

UmenR commented Jun 21, 2021

@nya-elimuai I have changed the title of the issue to better convey what we are looking for, My primary goal is to have some tests that can be run locally so that a developer can test the functionality of a particular endpoint without having to rely on the changes being pushed to TEST env.

@nya-elimu
Copy link
Member

nya-elimu commented Jun 21, 2021

@UmenR Ok, then let's also think about code coverage. By mocking the REST controller's response, which part(s) of the REST controller's code is actually being tested?

@UmenR
Copy link
Member Author

UmenR commented Jun 21, 2021

@nya-elimuai All handler methods within a REST controller should Ideally be covered In my opinion But for now, we can stick with adding tests for the controllers that we are currently working on and deal with the other when required. However, I'm also a little stumped when it comes to this matter especially with Creation/Update type of requests. We can discuss and fine-tune the details here.

What I have in mind is for Handler methods that handle GET type of requests[1], the entire handler method can be tested by mocking any read operations [1]. The PR already covers this [2]

But, the most useful part of adding mocks is to test requests that handle the creation/updating of resources. Especially since these are not covered anywhere as far as I know. But I need to do more research on this part E.G : The new WordContributionRestController[3] that is intended to be used by the crowdsource APP[3] Here we need to mock the persistence, and validation etc. will be covered by the test.

What do you think?

[1]https://github.com/elimu-ai/webapp/blob/master/src/main/java/ai/elimu/rest/v2/crowdsource/LetterToAllophoneMappingsController.java#L37toL56
[2]https://github.com/elimu-ai/webapp/pull/1315/files#diff-2351836a475664a950066a36208fd03c2788bd2d2a0a99f44b466658c4f90dee
[3]https://github.com/elimu-ai/webapp/blob/master/src/main/java/ai/elimu/rest/v2/crowdsource/WordContributionRestController.java#L60toL162

@UmenR
Copy link
Member Author

UmenR commented Jun 21, 2021

I just realized we have already opened an issue to create unit tests for POST requests here [1] . If required we can move the discussions related to mocking POST requests there.

[1] #1297

@nya-elimu
Copy link
Member

@UmenR I think Sorry, I still don't properly understand what will be tested if you mock a REST controller. Could you explain which lines of code will be covered with this type of test?

@nya-elimu
Copy link
Member

@UmenR Note that another pending issue is to configure code coverage on Jenkins: https://github.com/elimu-ai/webapp/projects/7#card-45361508

A code coverage tool would enable us to see how many lines of code have been covered by a unit test in each class/method. Maybe this would be useful to have before writing unit tests for mocked functionality?

@nya-elimu nya-elimu added the wontfix This will not be worked on label Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants