-
Notifications
You must be signed in to change notification settings - Fork 417
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
Mock mix pl tests #482
Mock mix pl tests #482
Conversation
Running |
Sooo, are there any opinions about this approach? Because i don't want to put more time into it if the approach is already not good. |
I missed this 20 days ago and I don't really have much time to dedicate to NewPipe currently, I may try to look at it the day after tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach, it allows for expansion and is simple to migrate to. Thank you for your dedication :-D
...test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java
Outdated
Show resolved
Hide resolved
...test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java
Outdated
Show resolved
Hide resolved
extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java
Show resolved
Hide resolved
extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java
Outdated
Show resolved
Hide resolved
RecordingDownloader relies on the real downloader and saves the request/response pair into a json file. MockDownloader uses json files from above and mocks responses for specific requests.
…ables. If the system property 'downloader' is set that use that specific downloader. This is used from gradle by appending `-Ddownloader=ABCD to the command. ABCD is one of DownloaderType. The other variable is the static property `DEFAULT_DOWNLOADER` in DownloaderFactory, which can be easily changed as needed inside the IDE according to development needs`. Normal workflow would be to first use the recording downloader and afterwards only use mocks, if the requests are always staying the same.
This is needed so that a request is made for each test class when running multiple at once. This way RecordingDownloader records all necessary requests. This works as long as tests are run sequentially and not in parallel.
Only read those files in MockDownloader
2883e4a
to
e82cb1e
Compare
@Stypox i rebased on top of dev. I will regenerate the mock files, when the pr is ready to be merged. edit: easier reviewing as in you only have to check the new commits. (after jsom generation) |
extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java
Outdated
Show resolved
Hide resolved
Can you put that info to a place where it can be found later? [To be honest, I don't know a good place for that] |
@TobiGr I added to the classes/methods themselves. Anywhere else it would just get out of date. Only thing thats missing is that CI jobs should use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready, imo
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this now looks good to me. Do you still want to implement something else or is this ready @XiangRongLin ? @TobiGr I'll let you merge, since you also reviewed this PR.
I'll just recreate the json files later. Then it can be merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me, and the relevant tests succeed. Great :-D
My first draft to address the points abount mocking the responses in #481. Not yet merge ready, but before that i wanted to get some opinions on this type of solution.
RecordingDownloader
relays request to the existing DownloaderTestImpl, but saves the request/response pair into a json file inside a folder specific to the test class. This should be done locally when the requests that are made by a test class change.MockDownloader
relies on the json files created by theRecordingDownloader
. PR/Push CI jobs should then use this downloader.DownloaderFactory.DEFAULT_DOWNLOADER
-Ddownloader=ABCD
, where ABCD is one ofDownloaderType
DownloaderFactory
. If none is giving it falls back to that one.Some sitenotes:
YoutubeParsingHelper
holds a global state about client version and client key. The first test class that gets executed with theRecordingDownloader
makes a request and gets that request saved. Other test classes also need that request saved, but since the global state is then already initialized, that request won't be made. Currently I added that request as shared and add them to allMockDownloader
sapache-commons-io can be removed if needed. Was needed to clear the directories beforeRecordingDownloader
fills them.gradle aggregatedJavadocs -Ddownloader=xyz
works because it won't work on windows due to file encoding. I only triedgradle extractor:test -Ddownloader=xyz
Ignore the first (move package) and last commit (generated jsons) for easier diffs