Passing JUnit data between tests

后端 未结 5 1216
鱼传尺愫
鱼传尺愫 2020-12-10 11:07

I just discovered when creating some CRUD tests that you can\'t set data in one test and have it read in another test (data is set back to its initialization between each te

5条回答
  •  [愿得一人]
    2020-12-10 11:52

    JUnit is independent test. But, If you have no ways, you can use "static" instance to store it.

    static String storage;
    @Test
    public void method1() {
        storage = "Hello"
    }
    
    @Test
    public void method2() {
        Assert.assertThat(something, is(storage));
    }
    

提交回复
热议问题