OFBiz
  1. OFBiz
  2. OFBIZ-1463

JUnit test case for various application components

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: Trunk
    • Fix Version/s: None
    • Component/s: framework
    • Labels:
      None
    • Sprint:
      Bug Crush Event - 21/2/2015

      Description

      This is an effort to create JUnit test suites for various bussiness processes in Ofbiz.
      It would be good to have such tests in place so that we can test Ofbiz on a certain day.

      These tests are in initial stage, so I would like community members to post there comments so that we can move
      ahead with them to make these test even better.

        Issue Links

          Activity

          Hide
          Vikas Mayur added a comment -

          Marco, you are most welcome to review and commit these patches.

          Show
          Vikas Mayur added a comment - Marco, you are most welcome to review and commit these patches.
          Hide
          Taher Alkhateeb added a comment -

          Hello everyone,

          It is important to note in here that the old OFBiz tests are really integration tests, not unit tests. Therefore, please note the following comments / recommendations:

          • If your test does not need a database or some environment context, then convert it to a unit test
          • Real unit tests are very fast, if it takes time (because of using external resources) then keep it as an integration test
          • Unit tests are automatically run everytime you call ./gradlew build or run any server commands.
          • Unit tests can be explicitly called by the command ./gradlew test
          • Recommend to keep the JUnit tests as pure junit (nothing OFBiz related)
          • Recommend using the annotations instead of starting each test name with test...
          • Highly recommend using ExpectedException and _assertThat(actual, expected) API over other older classical test methods.
          • You might need to create mock objects for your tests. This is where mockito might be helpful. I will propose something on the ML once I hit a test requirement to introduce it.

          I will create a Sub-JIRA to commit some tests for the Start component which you can use as a reference If you like to.

          Show
          Taher Alkhateeb added a comment - Hello everyone, It is important to note in here that the old OFBiz tests are really integration tests, not unit tests. Therefore, please note the following comments / recommendations: If your test does not need a database or some environment context, then convert it to a unit test Real unit tests are very fast, if it takes time (because of using external resources) then keep it as an integration test Unit tests are automatically run everytime you call ./gradlew build or run any server commands. Unit tests can be explicitly called by the command ./gradlew test Recommend to keep the JUnit tests as pure junit (nothing OFBiz related) Recommend using the annotations instead of starting each test name with test... Highly recommend using ExpectedException and _assertThat(actual, expected) API over other older classical test methods. You might need to create mock objects for your tests. This is where mockito might be helpful. I will propose something on the ML once I hit a test requirement to introduce it. I will create a Sub-JIRA to commit some tests for the Start component which you can use as a reference If you like to.
          Hide
          Jacques Le Roux added a comment -

          I know it's totally out of subject and certainly premature but should we not do that with http://junit.org/junit5/ in mind? Or even maybe play daredevils and use it already (after all it's trunk)?

          Show
          Jacques Le Roux added a comment - I know it's totally out of subject and certainly premature but should we not do that with http://junit.org/junit5/ in mind? Or even maybe play daredevils and use it already (after all it's trunk)?
          Hide
          Taher Alkhateeb added a comment -

          Hmmmmm, It is certainly doable with gradle. I think the technology is still beta and we are expected to make a release branch soon. Perhaps we can upgrade junit after the branch? As far as I know the syntax is very much the same and only new features are added such as the ability to use lambda expressions in assertions. So I think an upgrade is not difficult.

          Show
          Taher Alkhateeb added a comment - Hmmmmm, It is certainly doable with gradle. I think the technology is still beta and we are expected to make a release branch soon. Perhaps we can upgrade junit after the branch? As far as I know the syntax is very much the same and only new features are added such as the ability to use lambda expressions in assertions. So I think an upgrade is not difficult.
          Hide
          Pierre Smits added a comment - - edited

          We all know trunk can be a volatile branch and things can get broken from time to time, but that doesn't mean that is should be used as a testbed for some piece of 3rd party software the community has no experience with.

          That being said, why don't you do a Proof of Concept first in your own dev environment and share results with the community? So that it can look for follow-up actions.

          Show
          Pierre Smits added a comment - - edited We all know trunk can be a volatile branch and things can get broken from time to time, but that doesn't mean that is should be used as a testbed for some piece of 3rd party software the community has no experience with. That being said, why don't you do a Proof of Concept first in your own dev environment and share results with the community? So that it can look for follow-up actions.
          Hide
          Taher Alkhateeb added a comment - - edited

          Hello everyone, I've introduced unit tests to the start component in OFBIZ-7897 which helped me actually detect some minor errors in the code. If you wish you can use these tests as a reference of how to introduce unit tests utilizing gradle. These tests automatically run every time you call build, test, or run any of the server commands (upon any code change). If no change in the code is detected then the tests are cached and not run again (just like ant or any other build system)

          Show
          Taher Alkhateeb added a comment - - edited Hello everyone, I've introduced unit tests to the start component in OFBIZ-7897 which helped me actually detect some minor errors in the code. If you wish you can use these tests as a reference of how to introduce unit tests utilizing gradle. These tests automatically run every time you call build, test, or run any of the server commands (upon any code change). If no change in the code is detected then the tests are cached and not run again (just like ant or any other build system)

            People

            • Assignee:
              Unassigned
              Reporter:
              Vikas Mayur
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Development

                  Agile