Skip to content

Add simple Unit tests #6207

Closed
Closed
@koppor

Description

@koppor

JabRef offers unit testing based on JUnit5. There are still untested functionalities and not good tests. Here are some tasks in that field.

Please first read our writings on testing.

  • DO NOT ADD GUI TESTS AS THESE ARE NOT SIMPLE AT ALL
  • Create one pull request for one test class; this makes reviewing easier. If you change MinifyNameListFormatterTest, DOICheckTest, ... in one pull request, reviewing is hard, because they are all unrelated classes.

Unit test creation

Creating unit tests can be trained creating tests for classes residing in following packages

  • org.jabref.logic.integrity

(to be continued)

There is no need to test all classes. Just pick one or two. Testing takes time and one carefully needs to think about the intention of the class to be able to check user-centric good cases and bad case.

Please also think of adding documentation to https://github.com/JabRef/user-documentation after you understood the intension of the class.

Unit tests improvement

  • split multiple asserts into different test cases.
    It is an antipattern having multiple assert statements in a test case. Thus, they should be split - with meantingful test names

    Example:

       @Test
       void testNoteChecks() {
           assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX));
           assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX));
           assertWrong(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX));
           assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX));
           assertCorrect(withMode(createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX));
           assertCorrect(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBLATEX));
       }
  • Add paramaterized tests

  • org.jabref.logic.integrity.IntegrityCheckTest: split tests into tests for each integrity check class (e.g. checking editions should go to EditionChecker)

(to be continued)

Other tests to work on

Metadata

Metadata

Labels

dev: code-qualityIssues related to code or architecture decisions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions