在公司的案子是使用 SpringJUnit4AbstractClass
1.當然首先jar檔不能少:
pom.xml:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
2.SpringJUnit4AbstractClass:
package test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class SpringJUnit4AbstractClass {
public SpringJUnit4AbstractClass(){
super();
}
}
3. 要做的test頁面,假設要測會員 就取 memberTest:
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.neweb.twq.api.constant.CashPaymentType;
import com.neweb.twq.api.external.payment.cs.ICashPaymentService;
import com.neweb.twq.api.external.payment.cs.to.CashQueryOrdersRequest;
import com.neweb.twq.api.external.payment.cs.to.CashQueryOrdersResponse;
import test.SpringJUnit4AbstractClass;
public class memberTest extends SpringJUnit4AbstractClass{
@Autowired
IMemberService iMemberService;
@Test
public void testMemberId(){
memberData member = new memberData();
member.name = "KK";
String strAddr = iMemberService.search(member);
}
//@Test
public void testMemberName(){
..... more code
}
}
以上就是簡單的範例,如果要測哪個就把 @Test中的註解拿掉即可,全部@Test注解都拿掉擇全部都會執行
全站熱搜