我有这个类,里面有一个方法(随机化器)
public class WebDriverCustomMethods {
public int randomizer(int min, int max) {
int d = (max - min) + 1;
int c = min + (int) (Math.random() * ((d)));
return c;
}
我想在我的测试类中使用,如下所示:
public class AppTest3 {
public static DataProviderClass appdata;
public static WebDriverCustomMethods w;
public static void main (String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
appdata = (DataProviderClass) context.getBean("data");
w = (WebDriverCustomMethods) context.getBean("wdcm");
}
@Test(dataProvider="standardTestData", dataProviderClass=DataProviderClass.class)
public void oneUserTwoUser(WebDriver driver, WebDriverWait wait, ArrayList<ArrayList<String>> array) throws Exception {
int randomNumber = w.randomizer(1, 99999);
当我运行它并且代码开始使用 w.randomizer(1,9999) 时,我收到以下错误:
java.lang.NullPointerException
at com.f1rstt.tests.AppTest3.oneUserTwoUser(AppTest3.java:34) //this is int randomNumber = w.randomizer(1, 99999);
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
这是我的 spring.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "http://www.springframework.org/dtd/spring-beans-2.0.dtd" PUBLIC "-//SPRING//DTD BEAN 2.0//EN">
<beans>
<bean id="data" class="com.blah.tests.DataProviderClass"/>
<bean id="wdcm" class="com.blah.tests.WebDriverCustomMethods"/>
</beans>