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

simplify state sorting status unit test - avoid duplicated code in HtmlTreeBuilderStateTest.java #1157

Closed
wants to merge 1 commit into from

Conversation

ny83427
Copy link
Contributor

@ny83427 ny83427 commented Dec 13, 2018

In test file HtmlTreeBuilderStateTest it duplicated tags to search through and there is also a special hint to remind maintainer to synchronize these arrays whenever there is any newly added.

So I made a small improvement to access these arrays via reflection and I tested that the uni test execution time just slow down very little as I executed tests before and after several times.

@ny83427
Copy link
Contributor Author

ny83427 commented Dec 13, 2018

Just found that HtmlTreeBuilderTest and TokeniserStateTest have similar structure and requirement on newly added string array or char array. It's not a big deal but I think extract these kinds of tests would be beneficial. @jhy What you say?

image

List<String[]> arrays = new ArrayList<>(fields.length);
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && field.getType() == String[].class) {
Copy link
Owner

Choose a reason for hiding this comment

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

My main concern with changing the test to use reflection like this is that the test could, now or in the future, accidentally be skipping fields that need to be tested. E.g. what if down the line we add a constant and for some reason don't mark it final? (I know a bit of a forced example.)

I think if we also add an explicit test that there were n arrays matched it would be more explicit, and can keep a warning in the source to review the test.

Yes, would be good to update the other tests like this, and share a common piece of reflection code.

@ny83427
Copy link
Contributor Author

ny83427 commented Jan 9, 2019

Hi Jonathan, since this is not a big deal, and the minor copy+paste is more straight forward for unit test, I would like to drawback my PR and you may balance correspondingly. Thank you for your reply and consideration.

@ny83427 ny83427 closed this Jan 9, 2019
@ny83427 ny83427 deleted the simplify-html-tree-state-test branch January 9, 2019 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants