How can I improve my junit tests

后端 未结 9 850
南笙
南笙 2020-12-05 08:59

Right my junit tests look like a long story:

  • I create 4 users
  • I delete 1 user
  • I try to login with the deleted user and make sure it fails
9条回答
  •  被撕碎了的回忆
    2020-12-05 09:23

    You can use JExample, an extension of JUnit that allows test methods to have return values that are reused by other tests. JExample tests run with the normal JUnit plugin in Eclipse, and also work side by side with normal JUnit tests. Thus migration should be no problem. JExample is used as follows

    @RunWith(JExample.class)
    public class MyTest {
    
        @Test
        public Object a() { 
            return new Object();
        }
    
        @Test
        @Given("#a")
        public Object b(Object object) { 
            // do something with object
            return object; 
        }
    
        @Test
        @Given("#b")
        public void c(Object object) { 
            // do some more things with object
        }
    
    }
    

    Disclaimer, I am among the JExample developers.

提交回复
热议问题