Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-11323

Reduce boilerplate "System.setProperty" code in tests

    XMLWordPrintableJSON

Details

    • Test
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.8
    • None

    Description

      There are many examples in tests where some property gets new value in "beforeTestsStarted"/"beforeTest"/"beginning of test method" and then gets its previous value in "afterTestsStopped"/"afterTest"/"finally block of test method". This approach leads to excessive code that can be avoided.

      I suggest implementing annotation "WithSystemProperty" (name is the subject to discussion) that will allow us to write this:

      @Test
      @WithSystemProperty(key = IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, value = "true")
      public void testSkipCheckConsistencyFlagEnabled() throws Exception {
          ...
      }
      

      instead of this:

      @Test
      public void testSkipCheckConsistencyFlagEnabled() throws Exception {
          String backup = System.setProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, "true");
      
          try {
              ...
          }
          finally {
              if (backup != null)
                  System.setProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, backup);
              else
                  System.clearProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK);
          }
      }
      

       

      There also has to be ability to use this annotation on test class so new value of system properties will be used in all of its test methods.

      Attachments

        Issue Links

          Activity

            People

              ibessonov Ivan Bessonov
              ibessonov Ivan Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m