Skip to content

[Soundcloud] Initial soundcloud test refactoring#1324

Closed
absurdlylongusername wants to merge 9 commits intoTeamNewPipe:devfrom
absurdlylongusername:initial-soundcloud-test-refactoring
Closed

[Soundcloud] Initial soundcloud test refactoring#1324
absurdlylongusername wants to merge 9 commits intoTeamNewPipe:devfrom
absurdlylongusername:initial-soundcloud-test-refactoring

Conversation

@absurdlylongusername
Copy link
Copy Markdown
Member

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

Add test cases for SoundcloudStreamExtractorTest

This PR makes initial progress on refactoring testing infrastructure to use test cases to generate tests instead of current architecture that uses a class to define each test case.

It uses Immutables to define test cases. ISoundcloudStreamExtractorTestCase is the test case used for SoundcloudStreamExtractorTest, which inherits from other default extractor test cases.

In future PRs this will be expanded on to further decouple the current test format so we can have tests that can run multiple test cases instead of defining a new class for each test case. This will make tests easier to change, more versatile and extensible.

Update tests in SoundcloudStreamExtractorTest

Changed how the tests for SoundCloud CDN urls worked to use a regex instead of matching the ID explicitly.

Please Note

This PR includes changes from #1323 which couldn't be removed as it depends on it. However, since those changes don't depend on this, I have included them in that other PR so they can be merged first before this one.

@absurdlylongusername absurdlylongusername changed the title Initial soundcloud test refactoring [Soundcloud] Initial soundcloud test refactoring Jul 8, 2025
@TobiGr TobiGr added SoundCloud Service, https://soundcloud.com/ code quality Improvements to the codebase to improve the code quality tests Issues and PR related to unit tests labels Jul 8, 2025
…om Immutables test case object

Add Immutables annotation processor to gradle build
Add custom Immutables Style
Add ISoundcloudStreamExtractorTestCase for use in stream extractor tests
Refactor testAudioStreams to match mp3 cdn url by regex
… API <26)

Add javadocs to other methods in Parser.java
@absurdlylongusername absurdlylongusername force-pushed the initial-soundcloud-test-refactoring branch from cad1c80 to b89ac78 Compare July 8, 2025 13:00
Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this and sorry for the late review. While I do like the builder pattern better than test subclasses, I don't think it's worth to spend a lot of time to refactor all of the tests in the extractor to this pattern, for these reasons:

  • While the current test infrastructure might be a bit more verbose and/or have more boilerplate, it is also more flexible and easy to debug, as there is one less layer of abstraction that tests have to go through.
  • In most tests we just need to provide data to common testing methods that behave always the same. In these cases the builder pattern is the best solution. But in many cases throughout the extractor we have custom logic specific to a specific test: e.g. custom initialization of the extractor field, custom tests just for some cases, etc. I'm not saying there is no way to add specific logic with the builder pattern, but it would again not be super elegant.
  • The current way tests are setup might not be the best possible, but it has worked just fine so far, is easily extensible and involves only little boilerplate (you just need one line of code for each piece of data you want to specify, just like with the builder pattern, although there's less stuff around it).

I understand what you are trying to achieve with this PR and I see why you don't like how tests are setup right now. My points above are not meant to be in support of the status quo as the best solution, but rather try to argue why the current tests are already good enough and we wouldn't get much more value by refactoring them. Refactoring everything would take a lot of time, and given how repetitive it would be as a task, it will also be easy to make mistakes. I think that the value we would gain from refactoring to the builder pattern (in terms of better readability, easier testing, etc.) is very small.

What do other team members think? @TobiGr or @AudricV or @litetex? Also, in case we still decide to move forward, this will need a rebase.

@absurdlylongusername
Copy link
Copy Markdown
Member Author

@Stypox In hindsight, yes I do agree it's not worth doing this atm purely due to the fact it is not a priority right now, not absolutely necessary, and a lot of this test code is not being used/developed around that much.

That being said, I believe that tests and stuff that we add in the future should use a better pattern rather than the patterns that we use right now.

E.g. #1360 would require refactoring a lot of stuff around Soundcloud, and in turn would mean changing some tests and adding new tests. Ideally, I'd want these new tests to be made in a way where it's not a class per test case. Would you agree?


Also this kind of begs the question: how often do we need tests that have many test cases? Because we do indeed have some tests in our codebase that are structured like this and have several test cases (e.g. SoundcloudSteamLinkHandlerFactoryTest).

IIRC, my main rationale for wanting to do this refactor was that all tests should be extensible (in the dimension of being able to add more test cases) by default (i.e. it is the same test with multiple test cases, not a new test with @test annotation); but, if, realistically, most of the tests will not require this functionality then it's not much of a reward doing this refactor everywhere.

If tests with many test cases was a requirement or design concern, then the current test infrastructure that I want to refactor wouldn't have been designed the way it is. So, it makes sense for me to conclude that for most or all of the tests that have this current structure do not really require many test cases in order to be tested approriately.

So, practically, imo, if anything is going to be refactored it should only be done if the tests actually need to be expanded in the dimension of needing many test cases for tests, OR if that part of the code is already going to undergo a large enough structural change that refactoring it in the process can easily be done in parallel without much overhead.

Given this, this PR doesn't meet either of these criteria so it is not necessary and therefore can be abandoned.

@Stypox
Copy link
Copy Markdown
Member

Stypox commented Oct 2, 2025

Also this kind of begs the question: how often do we need tests that have many test cases?

If tests with many test cases was a requirement or design concern, then the current test infrastructure that I want to refactor wouldn't have been designed the way it is. So, it makes sense for me to conclude that for most or all of the tests that have this current structure do not really require many test cases in order to be tested approriately.

I would say that for remote content (videos, playlists, etc.) we don't usually need tests with many test cases:

  • usually we write tests for specific behaviors of services (e.g. a video being age restricted, not available, with/without comments, etc.), so it would not be very helpful to test the same behavior multiple times, as the format of data going in/out would basically be the same. Whenever we notice that the format of data differs (which usually means adding new conditions somewhere in an extractor), we usually also add a test.
  • already with the current amount of tests there is a considerable amount of maintenance, since whenever video authors change the title/description/... we also need to update the tests right after updating mocks. So tripling or quadrupling the amount of test cases would mean having to spend even more time updating mocks, fixing test case data, etc.

E.g. #1360 would require refactoring a lot of stuff around Soundcloud, and in turn would mean changing some tests and adding new tests. Ideally, I'd want these new tests to be made in a way where it's not a class per test case. Would you agree?

I think that for link handlers it makes a lot of sense to have test cases, because the link handler functions to test often have just a couple of inputs and outputs, and always the same amount thereof. Videos on the other hand have a lot of fields that should just default to some value, and we'd need the builder pattern to achieve something like that, which is already more verbose than just a list of test cases. But yeah we should definitely use test case lists (I don't know how to call it, maybe it's "instanced tests"?) for link handlers and other input->output functions.

So, practically, imo, if anything is going to be refactored it should only be done if the tests actually need to be expanded in the dimension of needing many test cases for tests, OR if that part of the code is already going to undergo a large enough structural change that refactoring it in the process can easily be done in parallel without much overhead.

This sounds like a good plan :-)

@Stypox Stypox closed this Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvements to the codebase to improve the code quality SoundCloud Service, https://soundcloud.com/ tests Issues and PR related to unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants