Search code examples
javajunithttp-unit

When are HttpUnitOptions automatically reset?


When using HttpUnit and setting options via the HttpUnitOptions class, when are the options reset to their defaults?

Are they reset at the beginning of every test, the test suite, the test runner, or the lifetime of the JVM ?

As an example and for context if I set

HttpUnitOptions.setDefaultCharacterSet("utf-8");

at the start of a given test, should I reset it by calling

HttpUnitOptions.setDefaultCharacterSet() 

at the end of the test, or is this redundant?


Solution

  • I am answering as one of the committers of the httpunit project

    Here is the source code of the base Class HttpUnitTest:

    public class HttpUnitTest extends HttpUserAgentTest {
    
        @Before
        /**
         * setup the test by resetting the environment for Http Unit tests
         */
        public void setUpHttpUnitTest() throws Exception {
            HttpUnitOptions.reset();
            HTMLParserFactory.reset();
        }
    

    as you can see this is how the HttpUnit test cases work themselves. The HttpUnitOptions are reset before each test is run so that each test can have individual options. Whether you do the same depends on your use-case. The HttpUnitOptions are abstract and never instantiated - they behave like a global variable so if you would like to be positively sure about their settings you need to reset them before setting your own state. If you'd like to have one state for all your tests it would be a different story.