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

test: improve the test for SpoonTagger class #3982

Merged
merged 2 commits into from
Jun 11, 2021
Merged

test: improve the test for SpoonTagger class #3982

merged 2 commits into from
Jun 11, 2021

Conversation

Rohitesh-Kumar-Jain
Copy link
Contributor

Hi, I have improved the mutation strength from 0% to 100% for the SpoonTagger class.

Here's the report before improvement.

Screen Shot 2021-06-08 at 22 20 25-fullpage

Actually, the test was poorly written, it had overlooked the scenario when the Spoon.java file already exists. I have taken care of that scenario and have manually tested the mutation "Removed all instructions in the method", and it is getting killed now.

I feel the PR is ready for merging.

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

#1818
Link to #3967

@slarse
Copy link
Collaborator

slarse commented Jun 8, 2021

Hi @Rohitesh-Kumar-Jain,

Just FYI I will get back to reviewing your PRs tomorrow, was a bit busy with other things today :)

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

reviewing your PRs tomorrow, was a bit busy with other things today :)

Yeah no problem

Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

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

This is a good find!

For tests that require that require a "clean slate" when running, it's better to use a temporary directory instead of deleting select files. You can easily create a temporary directory with JUnit5 like so:

@Test
public void testSpoonTagger(@TempDir File tempDir) {
    // contract: ...
    Launcher launcher = new Launcher();
    launcher.setSourceOutputDirectory(tempDir.getAbsolutePath());
    // do the test here
}

@@ -87,8 +87,13 @@ public void testRuntimeProcessorManager() {

@Test
public void testSpoonTagger() {
// contract: this tests the process method of the SpoonTagger class.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like I mentioned in the other review, a contract should state what is expected to happen given what the test does. An appropriate contract here would be: contract: after running SpoonTagger, the file spoon/Spoon.java should exist in the output directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for correcting the contract, I will make sure that future test contracts are more appropriate.

final Launcher launcher = new Launcher();
launcher.addProcessor("spoon.processing.SpoonTagger");
// we need to make sure that the spoon/Spoon.java file doesn't already exist in the system, as it will cause the assertion to be irrelevant
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an example of a good comment: it says why we do something.

final Launcher launcher = new Launcher();
launcher.addProcessor("spoon.processing.SpoonTagger");
// we need to make sure that the spoon/Spoon.java file doesn't already exist in the system, as it will cause the assertion to be irrelevant
File file = new File (launcher.getModelBuilder().getSourceOutputDirectory() + "/spoon/Spoon.java");
// deleting the Spoon.java if it exists
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an example of a bad comment: it just restates what the code does. The code already says that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out, I will avoid redundant comments in future

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that as with any rule of thumb, there are exceptions. Sometimes we simply fail to write code that is clear enough to be understood, and then we need to put a comment in to clarify. That wasn't the case here though, the code was very clear.

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

For tests that require that require a "clean slate" when running, it's better to use a temporary directory instead of deleting select files.

Thanks for letting me know this, I will keep this in my mind for future tests

@slarse
Copy link
Collaborator

slarse commented Jun 9, 2021

@Rohitesh-Kumar-Jain Given your responses I'm not sure it was clear, but my comments here were not meant only for future PRs, but for this one as well! You can see it as "changes requested" on the PR review. Please address the comments :)

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

@Rohitesh-Kumar-Jain Given your responses I'm not sure it was clear, but my comments here were not meant only for future PRs, but for this one as well! You can see it as "changes requested" on the PR review. Please address the comments :)

Ik this is meant for this PR only, I was saying that I will keep these things in my mind for future PRs.

@slarse
Copy link
Collaborator

slarse commented Jun 9, 2021

I was saying that I will keep these things in my mind for future PRs.

I understood that. What I did not know for sure was whether you understood that I meant for the comments to be fixed in this PR, and not only as suggestions for future PRs, and so I clarified the fact.

@slarse
Copy link
Collaborator

slarse commented Jun 10, 2021

@Rohitesh-Kumar-Jain This looks good to me, are you done here?

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

@Rohitesh-Kumar-Jain This good to me, are you done here?

Yes, this was a small class and I believe all 3 Descartes parameters have been improved to 100% 🎉

Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

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

@Rohitesh-Kumar-Jain

Yes, this was a small class and I believe all 3 Descartes parameters have been improved to 100%

That's excellent!

@monperrus ping for merge, one pseudo-tested method defeated!

@@ -86,8 +87,10 @@ public void testRuntimeProcessorManager() {
}

@Test
public void testSpoonTagger() {
public void testSpoonTagger(@TempDir File tempDir) {
// contract: after running SpoonTagger, the file spoon/Spoon.java should exist in the output directory
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Rohitesh-Kumar-Jain By the way, this is a well specified contract. Nice.

@monperrus monperrus changed the title review: test: improve the test for SpoonTagger class test: improve the test for SpoonTagger class Jun 11, 2021
@monperrus monperrus merged commit a4d3aaa into INRIA:master Jun 11, 2021
@monperrus
Copy link
Collaborator

one pseudo-tested method defeated!

Hurray, that's an achievement, per the plan pf GSOC!

@Rohitesh-Kumar-Jain thanks a lot for your patience and determination to understand what a good test is and how to improve Spoon's test suite.

@slarse thanks a lot for the mentoring

@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain deleted the improve-tests-for-spoontagger-class branch June 11, 2021 07:51
@monperrus monperrus mentioned this pull request Aug 19, 2021
woutersmeenk pushed a commit to woutersmeenk/spoon that referenced this pull request Aug 29, 2021
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.

3 participants