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

Add simple Unit tests #6207

Closed
koppor opened this issue Mar 29, 2020 · 8 comments
Closed

Add simple Unit tests #6207

koppor opened this issue Mar 29, 2020 · 8 comments
Assignees
Labels
type: code-quality Issues related to code or architecture decisions

Comments

@koppor
Copy link
Member

koppor commented Mar 29, 2020

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

@koppor koppor added the type: code-quality Issues related to code or architecture decisions label Mar 29, 2020
@dimitra-karadima
Copy link
Contributor

I'd like to work on that!

@koppor
Copy link
Member Author

koppor commented Apr 2, 2020

@dimitra-karadima Sure! Just go ahead. Please open a work-in-progress pull request after your first additions. I have no stron oppinion on which classes need testing and which test classes need restructuring. Just work on it as long as you feel comfortable.

dimitra-karadima added a commit to dimitra-karadima/jabref that referenced this issue Apr 4, 2020
Add the following changes:
-remove multiple assert statements in test cases
-split each assert statement in different test methods with meaningful
test names
@koppor koppor mentioned this issue Apr 22, 2020
5 tasks
koppor pushed a commit that referenced this issue May 13, 2020
Siedlerchr added a commit that referenced this issue May 16, 2020
* upstream/master: (50 commits)
  Keep group pane size when resizing window (#6180) (#6423)
  Changelog: Fix missing citation for biblatex-mla
  Update AUTHORS
  Check duplicate DOI (#6333)
  Fix missing citation for biblatex-mla
  Change EasyBind dependency (#6480)
  Add testing of latest dev version as mandatory
  Squashed 'src/main/resources/csl-styles/' changes from 5dad23d..586e0b8
  Fix libre office connection and other progress dialogs (#6478)
  Fix clear year and month field when converting to biblatex (#6434)
  Add truncate as a BibTex key modifier (#6427)
  Add new authors (not all - they need more work)
  Remove empty line
  Add simple Unit Tests for #6207 (#6240)
  Enforce LeftCurly rule (#6452)
  Implement task progress indicator (and dialog) in the toolbar (#6443)
  Consider empty brackets
  Changelog update
  Added a test
  Fixed brackets in regular expressions
  ...
@robert-do
Copy link

Hello koppor
Lars and I have chosen the project which is related to this task. We wanted to ask you whether you can recommend us some specific functions which we could write a test for as part of the project which will benefit you the most.
Kind regards,
Robert

@koppor
Copy link
Member Author

koppor commented Oct 28, 2020

Dear Lars and Robert,

We aim for 100% code coverage. You can check existing coverage with IntellIJ or Eclipse. You should see which classes have not that many test

Update Do not force the 100% coverage; think of good tests. For instance, test hard things such as unlinked files (see koppor#484 ) instead of tostring. See also https://ondrej-kvasnovsky.medium.com/is-100-test-coverage-worth-it-2e086ca4d41c and https://blog.ndepend.com/aim-100-percent-test-coverage/

I would love to see automated tests for features described in the user documentation. However, this is much work.

I assume you checked the integrity package (mentioned in the issue description) for current test coverage?

Cheers,

Oliver

@nasdas-dev
Copy link
Contributor

nasdas-dev commented Mar 9, 2021

Hi Oliver

We are a group of four MSc students from the University of Zurich, @ningxie1991, @BShaq, @Davfon, and myself @nasdas-dev.
As part of a software testing course we are enrolled in, we would like to contribute to this project over the next few weeks and increase the total code coverage as much as we can.

We created a new fork (ningxie1991/jabref) and work on our individual branches there. We will then create a pull request after each segment of work we have completed and reference this issue ticket.

Let us know if that works for you!
Best Regards
Dario

@Siedlerchr
Copy link
Member

For anyone else wanting to contribute some Unit Tests. The TemplateExporter currently have not yet any unit tests, that would also be a great improvement

@koppor
Copy link
Member Author

koppor commented Apr 19, 2021

Testing should aim for discovering bugs and ease maintenance of code. Thus, test real functionality. Do not test simple getters or toString methods! Tests should focus on ensuring that code change keep desired customer functionality.

@tobiasdiez
Copy link
Member

Given the amazing progress over the last few days (especially once all of the above PRs are merged), should we close this issue and return to our "only refactor if you work on this part of the code anyway" policy?

(Then I would also suggest to copy most of the issue text to the contribution guide / how to write tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

No branches or pull requests

6 participants