-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Enhance consistency check tests #13788
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
base: main
Are you sure you want to change the base?
Enhance consistency check tests #13788
Conversation
URL originUrl = ArgumentProcessorTest.class.getResource("origin.bib"); | ||
assertNotNull(originUrl, "Test resource origin.bib not found on classpath"); | ||
String fullBib = Path.of(originUrl.toURI()).toAbsolutePath().toString(); | ||
|
||
URL auxUrl = ArgumentProcessorTest.class.getResource("paper.aux"); | ||
assertNotNull(auxUrl, "Test resource paper.aux not found on classpath"); |
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 believe this is not correct.
Test should assert if auxImport works and not if Path.of or getResource works (the are covered by the jdk test suite) or if the resources are there.
If the test fails, because the test resources are not there, this should be "more dramatic" than "just" to assert if the logic does not work. This is a different scope and a different level of abstraction.
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.
Also can you confirm about auxImport test ? I am looking for solution to put the @BeforeAll annotation to checkTestResources() and remove per-test assertNotNull calls from auxImport test and it will be performed by class-level check. Am I thinking in right direction ?
Just a quick thought in between things |
Sure, I'll fix it. Thanks |
@Jenish-1235 Some small comment on the commit message - a commit message should be able to form a corerct sentence in case following is put BEFORE the message: "If applied, this commit will". Update: Link: https://www.gitkraken.com/learn/git/best-practices/git-commit-message#using-imperative-verb-form |
Sure, I'll take care of this as well. |
…cy-check-running-again
…e all to check for resources
…tps://github.com/Jenish-1235/jabref into task-get-test-of-consistency-check-running-again
fa0c7a0
to
52c6ba4
Compare
// Validate the produced bib can be parsed and contains at least one entry | ||
BibtexImporter importer = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()); | ||
List<BibEntry> entries = importer.importDatabase(outputBib).getDatabase().getEntries(); | ||
assertTrue(entries != null && !entries.isEmpty(), "Expected output bib to contain at least one entry"); |
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.
Typically, we match List.of(entry, ...)
to compare the contents. I can relate that this is not necessary here.
You can keep the idea assertFalse(entries.isEmpty()
-- the non-null is implicitly checked.
We typically also do not have assertion text, but since AI always generates it, it is OK to keep.
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.
While, I wrote the initial code as you mentioned as per typical style and upon using AI tools for code review, this changes were suggested. I will be open to learn the nuances of both, and make changes if needed.
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.
Being a new contributor, I wish to learn if this test-style is better in coding practices as entries won't be empty right ?
assertFalse(entries.isEmpty(), "Expected output bib to contain at least one entry");
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib")) | ||
.toURI() | ||
); | ||
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib")) |
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.
There is also the test at the beginning - not sure why this check is added here again.
…ck-running-again' into task-get-test-of-consistency-check-running-again
…ck-running-again' into task-get-test-of-consistency-check-running-again
…ck-running-again' into task-get-test-of-consistency-check-running-again
@trag-bot didn't find any issues in the code! ✅✨ |
@Jenish-1235 you don't need to merge main so often on Github. If you see here on GitHub that there is a conflict, that's when you should resolve and merge as soon as feasible. |
Alright will follow that. While as a practice I was trying to keep the branch updated. |
That is a good practice, but the people subscribed to the PR will keep receiving emails. |
Ahh got it , thanks for guiding 😄 |
void auxImport(@TempDir Path tempDir) throws URISyntaxException { | ||
String fullBib = Path.of(ArgumentProcessorTest.class.getResource("origin.bib").toURI()).toAbsolutePath().toString(); | ||
String auxFile = Path.of(ArgumentProcessorTest.class.getResource("paper.aux").toURI()).toAbsolutePath().toString(); | ||
void auxImport(@TempDir Path tempDir) throws IOException { | ||
InputStream originIs = ArgumentProcessorTest.class.getResourceAsStream("origin.bib"); | ||
InputStream auxIs = ArgumentProcessorTest.class.getResourceAsStream("paper.aux"); |
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.
Why this change? The tests worked bevor, didn't they?
assertTrue(Files.exists(outputBib)); | ||
BibtexImporter importer = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()); | ||
List<BibEntry> entries = importer.importDatabase(outputBib).getDatabase().getEntries(); | ||
assertTrue(entries != null && !entries.isEmpty(), "Expected output bib to contain at least one entry"); |
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.
Do assertNotEquals(List.of(), entries);
; -- null
check is included in assertNotEquals
.
IntelliJ will output the diff better in case of an error.
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib")) | ||
.toURI() | ||
); | ||
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib")) | ||
.toURI()); |
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.
Also remove requireNonNull
- to have the tests as clean as the other ones.
@ParameterizedTest(name = "Resource {0} is available on classpath") | ||
@CsvSource({"origin.bib", "paper.aux", "ArgumentProcessorTestExportMatches.bib"}) | ||
void checkTestResourcesParam(String resource) { | ||
assertNotNull(ArgumentProcessorTest.class.getResource(resource), "Required test resource missing from classpath: " + resource); | ||
} |
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.
Hi, FYI: We had some discussion in the devcal about this smoke test.
We came to the conclusion, that usually these tests are not neccessary.
It came down to that: JUnit is for testing code, not your build system: Using JUnit to check whether the resources are placed correctly is redundant as the build tool is already designed to manage that.
And Classpath/resource loading failures will show up anyway: If a test relies on a missing resource, it will throw an exception and fail.
So this is not really a unit test, but probably more of an integration test.
But, as we are always paranoid about our test setup, we will leave it in. 😄
Closes #13709
Steps to test
Mandatory checks
CHANGELOG.md
in a way that is understandable for the average user (if change is visible to the user)