title: value of global variable is changing to null in JUnit
body: <p>I wrote a simple class, in which first function's output is second function's input and second function's output is third function's input.
  After that I am printing these outputs in another class which implements JUnit @Test cases.</p>
  
  <p>But for call to second function's test, I'm getting 'res' value as null(which should be output of first function and passing it as input to second function). Same is the case with third function.</p>
  
  <p>I'm declaring 'res' as global variable. Then why is its value changing to null instead of holding the result of first function and then of second function( for call to third function) ?</p>
  
  <p>Here is the class which contains 3 functions:</p>
  
  <pre><code>package con.nc.junitexmples.Junit4Examples;
  
  public class StringExample {
  
   public static String firstFunction() {
  
      String msg1 = "msg1";
      return msg1;
  
  }
  
  public static String secondFunction(String msg1) {
  
      String msg2 = msg1+"msg2";
      return msg2;
  
  }
  
  public static String thirdFunction(String msg2) {
  
      String msg3= msg2+"msg3";
      return msg3;
  
    }
  
  }
  </code></pre>
  
  <p>Here is class which implements JUnit @Test cases and printing output: </p>
  
  <pre><code>package con.nc.junitexmples.Junit4Examples;
  
  import org.junit.After;
  import org.junit.AfterClass;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.FixMethodOrder;
  import org.junit.Test;
  import org.junit.runners.MethodSorters;
  
  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  
  public class TestStringExample {
  
  String res;
  
    @BeforeClass  
      public static void setUpBeforeClass() throws Exception {  
        System.out.println("\n\t\t-----JUnit cascading input Example------\n\n");  
        System.out.println("before class----&gt;only once");  
  
  
      }  
      @Before  
      public void setUp() throws Exception {  
          System.out.println("\nbefore---&gt;before each test case");  
      }  
  
      @Test  
      public void testFirstFunction(){  
          System.out.println("\ttest case: FIRST Function");  
  
          res = StringExample.firstFunction();
          System.out.println("\t"+res);
  
      }  
  
      @Test  
      public void testSecondFunction(){  
          System.out.println("\ttest case: SECOND Function");  
  
          res = StringExample.secondFunction(res);
          System.out.println("\t"+res);
  
      }  
  
      @Test  
      public void testThirdFunction(){  
          System.out.println("\ttest case: THIRD Function");  
  
          res = StringExample.thirdFunction(res);
          System.out.println("\t"+res);
  
      }  
  
  
      @After  
      public void tearDown() throws Exception {  
          System.out.println("after ---&gt; after each test case\n\n");  
      }  
  
      @AfterClass  
      public static void tearDownAfterClass() throws Exception {  
          System.out.println("after class---&gt;only once");  
      }  
  
  }
  </code></pre>
  
  <p>And here is the output I'm getting:</p>
  
  <pre><code>    -----JUnit cascading input Example------
  
  
   before class----&gt;only once
  
   before---&gt;before each test case
       test case: FIRST Function
       msg1
   after ---&gt; after each test case
  
  
  
   before---&gt;before each test case
       test case: SECOND Function
      **nullmsg2** 
   after ---&gt; after each test case
  
  
  
   before---&gt;before each test case
      test case: THIRD Function
       **nullmsg3**
   after ---&gt; after each test case
  
  
  after class---&gt;only once
  </code></pre>
  
  <p>How do I pass result of first function to second as input and so on?</p>