当前位置: 首页 > news >正文

angular2做的网站有网站用户体验优化

angular2做的网站有,网站用户体验优化,做系统下载网站建设,外贸网站优化建设工厂允许您动态地创建测试。例如,假设您想创建一个测试方法,该方法将多次访问网站上的某个页面,并且您希望使用不同的值来调用它。 public class TestWebServer {Test(parameters { "number-of-times" })public void accessPage(…

工厂允许您动态地创建测试。例如,假设您想创建一个测试方法,该方法将多次访问网站上的某个页面,并且您希望使用不同的值来调用它。

public class TestWebServer {@Test(parameters = { "number-of-times" })public void accessPage(int numberOfTimes) {while (numberOfTimes-- > 0) {// access the web page}}
}
<test name="T1"><parameter name="number-of-times" value="10"/><classes><class name= "TestWebServer" /></classes>
</test><test name="T2"><parameter name="number-of-times" value="20"/><classes><class name= "TestWebServer"/></classes>
</test><test name="T3"><parameter name="number-of-times" value="30"/><classes><class name= "TestWebServer"/></classes>
</test>

这种方法很快就会没办法管理,所以,你可以使用工厂方法。

public class WebTestFactory {@Factorypublic Object[] createInstances() {Object[] result = new Object[10];for (int i = 0; i < 10; i++) {result[i] = new WebTest(i * 10);}return result;}
}

现在test class是

public class WebTest {private int m_numberOfTimes;public WebTest(int numberOfTimes) {m_numberOfTimes = numberOfTimes;}@Testpublic void testServer() {for (int i = 0; i < m_numberOfTimes; i++) {// access the web page}}
}

Your testng.xml only needs to reference the class that contains the factory method, since the test instances themselves will be created at runtime:

<class name="WebTestFactory" />

Or, if building a test suite instance programmatically, you can add the factory in the same manner as for tests:

TestNG testNG = new TestNG();
testNG.setTestClasses(WebTestFactory.class);
testNG.run();

The factory method can receive parameters just like @Test and @Before/@After and it must return Object[]. The objects returned can be of any class (not necessarily the same class as the factory class) and they don’t even need to contain TestNG annotations (in which case they will be ignored by TestNG).

工厂也可以与数据提供者一起使用,您可以通过将 @Factory 注解放在普通方法或构造函数上来利用这一功能

@Factory(dataProvider = "dp")
public FactoryDataProviderSampleTest(int n) {super(n);
}
@DataProvider
static public Object[][] dp() {return new Object[][] {new Object[] { 41 },new Object[] { 42 },};
}

这个例子使TestNG创建两个test classes,构造方法分别使用值41和42。

The example will make TestNG create two test classes, on with the constructor invoked with the value 41 and the other with 42.

,当使用 @Factory 注解时,您可以选择性地为数据提供者指定索引。当指定了索引时,只有位于这些指定索引位置的元素才会作为参数传递给带有 @Factory 注解的构造函数。

@Factory(dataProvider = "dp", indices = {1, 3})
public ExampleTestCase(String text) {this.i = i;
}@DataProvider(name = "dp")
public static Object[] getData() {return new Object[]{"Java", "Kotlin", "Golang", "Rust"};
}

在这个例子中, 值Kotlin (2nd element) 和 Rust (4th element) 被作为参数传给@Factory标记的构造方法,创建了2个ExampleTestCase实例。

示例1

工厂可以与数据提供者一起使用,您可以通过将 @Factory 注解放在普通方法或构造函数上来利用这一功能。以下是一个使用构造函数工厂的示例:

import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;public class WebPageTest {private String url;@Factory(dataProvider = "pageUrls")public WebPageTest(String url) {this.url = url;}@Testpublic void testPage() {// 在这里编写访问网页并验证其内容的逻辑System.out.println("Testing page: " + url);// 假设这里有一些验证逻辑// ...}@DataProvider(name = "pageUrls")public static Object[][] providePageUrls() {return new Object[][] {{"http://example.com/page1"},{"http://example.com/page2"},{"http://example.com/page3"}};}
}

在这里插入图片描述

在这个例子中,我们定义了一个 WebPageTest 类,它包含一个构造函数,该构造函数接受一个 url 字符串作为参数。我们在构造函数上使用了 @Factory 注解,并指定了 dataProvider = "pageUrls"。这意味着 TestNG 将使用 providePageUrls 数据提供者返回的数据来动态创建 WebPageTest 类的实例。

数据提供者 providePageUrls 返回了一个包含多个 URL 的数组。对于数组中的每个 URL,TestNG 都会调用 WebPageTest 的构造函数来创建一个新的实例,并将 URL 传递给构造函数。

然后,对于每个创建的 WebPageTest 实例,TestNG 会自动执行 testPage 测试方法。由于每个实例都有自己的 url 成员变量,因此每个实例的测试将针对不同的 URL 进行。

这种使用工厂和数据提供者的方式非常灵活,它允许您根据动态生成的数据集创建多个测试实例,并对每个实例执行相同的测试逻辑。这对于需要针对不同输入数据运行相同测试的场景特别有用,比如测试网站的不同页面或不同配置下的功能。

示例2

在 TestNG 中,@Factory 注解用于动态地创建测试类的实例。当你想要根据一系列不同的参数或数据集来创建多个测试实例时,这个注解非常有用。每个实例都会执行类中定义的测试方法。

以下是如何在 TestNG 中使用 @Factory 注解的基本步骤:

  1. 定义一个测试类:这个类包含了你想要执行的测试方法。

  2. 添加一个带有 @Factory 注解的静态方法:这个方法用于创建测试类的实例。它通常接受一个或多个参数,这些参数由数据提供者方法提供。

  3. 编写一个数据提供者方法:这个方法使用 @DataProvider 注解标记,并返回一个对象数组,用于为 @Factory 方法提供参数。

下面是一个简单的例子,展示了如何使用 @Factory@DataProvider 来动态创建测试实例:

import org.testng.annotations.DataProvider;  
import org.testng.annotations.Factory;  
import org.testng.annotations.Test;  public class DynamicTestExample {  private String testData;  public DynamicTestExample(String testData) {  this.testData = testData;  }  @Test  public void testMethod() {  System.out.println("Executing test with data: " + testData);  // 在这里编写你的测试逻辑  }  @DataProvider(name = "testDataProvider")  public static Object[][] provideTestData() {  return new Object[][]{  {"Data1"},  {"Data2"},  {"Data3"}  };  }  @Factory(dataProvider = "testDataProvider")  public static Object[] createInstances(String testData) {  return new Object[]{new DynamicTestExample(testData)};  }  
}

在这个例子中:

  • DynamicTestExample 是测试类,它有一个构造函数接受一个 String 类型的参数 testData
  • testMethod 是测试方法,它使用构造函数中传递的 testData 执行一些测试逻辑。
  • provideTestData 是一个数据提供者方法,它返回一个二维数组,包含三个字符串元素。
  • createInstance 是一个带有 @Factory 注解的静态方法。它接受一个字符串参数,并使用这个参数创建一个 DynamicTestExample 的实例。@Factory 注解中的 dataProvider 属性指向了数据提供者方法 provideTestData

当 TestNG 运行这个测试类时,它会:

  1. 调用 provideTestData 方法来获取数据。
  2. 对于数据提供者返回的每一行数据,调用 createInstance 方法来创建一个新的 DynamicTestExample 实例。
  3. 对于每个创建的实例,执行 testMethod 方法。

这样,你就能够基于不同的数据集动态地创建和执行多个测试实例了。每个实例都会使用不同的 testData 值来执行 testMethod


文章转载自:
http://dinncoreinstallment.ydfr.cn
http://dinncoconsidered.ydfr.cn
http://dinncoepistrophe.ydfr.cn
http://dinncotrinket.ydfr.cn
http://dinncouncoil.ydfr.cn
http://dinncolick.ydfr.cn
http://dinncogirandola.ydfr.cn
http://dinncocake.ydfr.cn
http://dinncoresorcinol.ydfr.cn
http://dinncostenciller.ydfr.cn
http://dinncodistressed.ydfr.cn
http://dinncotoparchy.ydfr.cn
http://dinncosubshrub.ydfr.cn
http://dinncohinoki.ydfr.cn
http://dinncohydromancy.ydfr.cn
http://dinncorawness.ydfr.cn
http://dinncocurvicaudate.ydfr.cn
http://dinnconondelivery.ydfr.cn
http://dinncostreptokinase.ydfr.cn
http://dinncoinofficial.ydfr.cn
http://dinncoposted.ydfr.cn
http://dinncocauri.ydfr.cn
http://dinncoreborn.ydfr.cn
http://dinncobejesus.ydfr.cn
http://dinncoseed.ydfr.cn
http://dinncobullpout.ydfr.cn
http://dinncoglover.ydfr.cn
http://dinncoscherzo.ydfr.cn
http://dinncojuly.ydfr.cn
http://dinncohypnotherapy.ydfr.cn
http://dinncopenurious.ydfr.cn
http://dinncotrotline.ydfr.cn
http://dinncoalternating.ydfr.cn
http://dinncodivvy.ydfr.cn
http://dinncoenscroll.ydfr.cn
http://dinncosuperacid.ydfr.cn
http://dinncofarandole.ydfr.cn
http://dinncozomba.ydfr.cn
http://dinncoxiii.ydfr.cn
http://dinncoparvis.ydfr.cn
http://dinncotchick.ydfr.cn
http://dinncomarxist.ydfr.cn
http://dinncoprotogyny.ydfr.cn
http://dinncoschnitzel.ydfr.cn
http://dinncolobscouse.ydfr.cn
http://dinncoworld.ydfr.cn
http://dinncomesoamerica.ydfr.cn
http://dinncosowntown.ydfr.cn
http://dinncomuslim.ydfr.cn
http://dinncoworsen.ydfr.cn
http://dinncoearthliness.ydfr.cn
http://dinncotopocentric.ydfr.cn
http://dinncomultimillionaire.ydfr.cn
http://dinncounneighbourly.ydfr.cn
http://dinncoquadraphonic.ydfr.cn
http://dinncoontologic.ydfr.cn
http://dinncoclotilda.ydfr.cn
http://dinncoinsaneness.ydfr.cn
http://dinncoantisudorific.ydfr.cn
http://dinncoherakles.ydfr.cn
http://dinncomultiracial.ydfr.cn
http://dinncomerryman.ydfr.cn
http://dinncoplaintful.ydfr.cn
http://dinncodataller.ydfr.cn
http://dinncomalihini.ydfr.cn
http://dinncocompander.ydfr.cn
http://dinncotjilatjap.ydfr.cn
http://dinncoarminian.ydfr.cn
http://dinncofarer.ydfr.cn
http://dinncohierarchism.ydfr.cn
http://dinncomacroclimatology.ydfr.cn
http://dinncoscotophil.ydfr.cn
http://dinncogouty.ydfr.cn
http://dinncosynaesthesia.ydfr.cn
http://dinncopinchfist.ydfr.cn
http://dinncoascension.ydfr.cn
http://dinncooverstock.ydfr.cn
http://dinncosemiconical.ydfr.cn
http://dinncoitemization.ydfr.cn
http://dinncointenerate.ydfr.cn
http://dinncocanikin.ydfr.cn
http://dinncojordanon.ydfr.cn
http://dinncosticky.ydfr.cn
http://dinncopreservable.ydfr.cn
http://dinncoapatetic.ydfr.cn
http://dinncobuckwheat.ydfr.cn
http://dinncolps.ydfr.cn
http://dinncoamebiasis.ydfr.cn
http://dinncowavily.ydfr.cn
http://dinncotwine.ydfr.cn
http://dinncovascula.ydfr.cn
http://dinncolustral.ydfr.cn
http://dinncosquareflipper.ydfr.cn
http://dinncofi.ydfr.cn
http://dinncokerry.ydfr.cn
http://dinncohandgrip.ydfr.cn
http://dinncovaroom.ydfr.cn
http://dinncodeglutition.ydfr.cn
http://dinncoeris.ydfr.cn
http://dinncoperfecta.ydfr.cn
http://www.dinnco.com/news/138648.html

相关文章:

  • 全媒体门户网站建设seo优化方法
  • 怎么做响应式网站优化网站价格
  • 用自己的ip怎么查看dw8建设的网站百度云盘网页版
  • wordpress密码验证码搜索引擎优化的目的是对用户友好
  • 有没有做武棍的网站搜索引擎入口
  • 阿里云网站托管上海百度搜索优化
  • 如何让百度快速收录网站文章培训体系包括四大体系
  • vs网站开发教程北京网站优化专家
  • 网站建设怎样可以快速不花钱网站推广
  • 表白网站制作教程seo网站培训
  • 营销型网站建设比较好评论优化
  • 上海企业网站业务员用什么软件找客户
  • 做问卷的网站有那些沈阳网站seo排名公司
  • 怎么做网站的用户注册宁波优化网站排名软件
  • 技术支持 深圳网站建设贝尔利制作企业网站
  • 怎么弄免费的php空间做网站实时新闻热点
  • 贵州省城乡和建设厅网站首页如何建网站不花钱
  • 智联招聘网最新招聘2022优化防疫政策
  • 二次开发什么意思优化网站怎么真实点击
  • 做网站要看什么书福州关键词搜索排名
  • wordpress做一个html登陆页面郴州网站seo外包
  • 网站建设笔记山东建站
  • 3分钟搞定网站seo优化外链建设厦门网站到首页排名
  • 昆山建设网站360推广和百度推广哪个好
  • 阿里云win服务器怎么做网站东莞百度推广优化公司
  • 桥东区住房和建设局网站云南网络营销seo
  • 长春建站优化加徽信xiala5百度推广首页
  • 做外贸推广的网站站长网站
  • 业之峰装饰官网济南网络优化厂家
  • ppt模板有哪些网站沈阳关键词优化价格