Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

junit - Java unit test for different input data

I need to test some api. For example I have multiple @Test methods in the class to test my functionality, before init I connect to some url of my service, and use it.

If I have my service at multiple urls(different server environments), how can I Test this functionality for different service urls?

Flow:

  1. Init conncetion by url
  2. Run all Tests
  3. Init conncetion by another url
  4. Run all Tests(the same)
  5. ...

when was only one host I do like this:

public class TestAPI{
    @org.junit.Before
    public void init() {
      service = new Service("www.test.com");
    }
    @org.junit.Test
    public void testA(){
      service.CallA(); 
    }
    @org.junit.Test
    public void testB(){
     service.CallB(); 
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Happen to me sometime, and them I found this awesome idea called Parameterized Test, for instance: http://www.mkyong.com/unittest/junit-4-tutorial-6-parameterized-test/ in this way you can all the same tests couple of time with different argument.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...