RepoSense icon indicating copy to clipboard operation
RepoSense copied to clipboard

GitTestTemplate: `generateTestFileInfo` method is not reusable due to side effects

Open anubh-v opened this issue 4 years ago • 6 comments

I wish to clarify why the generateTestFileInfo method (a utility method in the test code) also updates the RepoConfiguration object used in the tests.

https://github.com/reposense/RepoSense/blob/145a1b4dda02ac9fdc42554835e7be98a534b0a0/src/test/java/reposense/template/GitTestTemplate.java#L90-L100

Shouldn't each test case update the RepoConfiguration on its own, if needed? I.e., if a test case needs to track MAIN_AUTHOR and FAKE_AUTHOR, the config can be updated separately in the test case? Alternatively, perhaps we should document why generateTestFileInfo does this?

anubh-v avatar Mar 09 '20 09:03 anubh-v

@jylee-git, may I check this with you?

One implication of this is whenever we extend GitTestTemplate and form a new subclass for testing, we have to be aware that generateTestFileInfo will modify the RepoConfiguration

anubh-v avatar Mar 09 '20 11:03 anubh-v

Two test cases are affected if we remove line 96 and 97. They are FileAnalyzerTest#blameTest and FileAnalyzerTest#blameTestDateRange

I'll check if these tests could be refactored

anubh-v avatar Mar 09 '20 14:03 anubh-v

@jylee-git @fzdy1914, I think we should remove the modifications to config in the generateTestFileInfo method (i.e. remove line 96 and 97)

Reason: I think the config setup should be done outside of generateTestFileInfo so that generateTestFileInfo can be used by more tests.

Currently, we cannot use generateTestFileInfo in a test if these modifications to config affect the test.

Shall we remove lines 96, and 97?

anubh-v avatar Mar 26 '20 07:03 anubh-v

Not sure though. Many test code are written in early stage of RepoSense, so it is possible to have code that is not so sound.

If we remove the two lines in this helper method, then, it seems to be a bit meanless to have this one line code method.

fzdy1914 avatar Mar 27 '20 09:03 fzdy1914

Not sure the reason behind it either, seconding what @fzdy1914 said about test codes being written in the early stages.

But I agree that the config of authors and its' respective aliases should be done on individual test case itself.

And probably call respective generateFileInfo methods directly instead of going through GitTestTemplate#generateTestFileInfo and/or GitTestTemplate#getFileResult if these two methods no longer serve any added value when the two lines of code are removed?

jinyao-lee avatar Mar 30 '20 15:03 jinyao-lee

Ok, I'll take a look and see if we should remove GitTestTemplate#generateTestFileInfo and GitTestTemplate#getFileResult

anubh-v avatar Apr 01 '20 15:04 anubh-v

I will be looking into this.

lawwm avatar Oct 12 '22 14:10 lawwm