代码解释-Java新功能-测试自动化框架

代码解释-Java新功能-测试自动化框架,java,Java,我是Java新手,正在尝试开发测试自动化框架。我一直在学习教程。我正在努力理解一些代码。如果有人能一步一步地解释代码是如何工作的或任何参考资料,那将是非常棒的。感谢是前进 @Test NewPostPage.CreatePost("This is the test post title").WithBody("Hi, this is the body").publish(); } 我会解释代码,因为这是你问的 这是一个静态方法,意味着它是一个类级方法,而不是实例级方法。您可以使用

我是Java新手,正在尝试开发测试自动化框架。我一直在学习教程。我正在努力理解一些代码。如果有人能一步一步地解释代码是如何工作的或任何参考资料,那将是非常棒的。感谢是前进

@Test 

   NewPostPage.CreatePost("This is the test post title").WithBody("Hi, this is the body").publish();



} 我会解释代码,因为这是你问的

这是一个静态方法,意味着它是一个类级方法,而不是实例级方法。您可以使用类名后跟方法名来调用它

NewPostPage.CreatePost() 
它的定义是

public static CreatePostCommand CreatePost(String title)
它返回带有适当参数的
CreatePostCommand
对象

return new CreatePostCommand(title);
CreatePostCommand
的构造函数采用单个字符串

public CreatePostCommand(String title){
    this.title=title;
}
然后,有一个来自
WithBody
方法的构建器模式。构建器模式的目的是将多个
与单个行上的x
调用链接在一起,而不是对
setX
setY
方法使用多行。每个
WithX
调用都返回它正在构建的对象

return this;
现在,我猜你漏掉了发布方法?但你所拥有的一切都相当于这个

CreatePostCommand postCmd = NewPostPage.CreatePost("This is the test post title");
postCmd = postCmd.WithBody("Hi, this is the body");
postCmd.publish();

您正在尝试开发一个测试自动化框架?为什么?现在已经有三个很好的选项(JUnit、TestNG、Spock),最好从一个更简单的项目开始。即使只是提到这个问题,您也向我们抛出了一些样板代码,要求我们解释一些内容,但其中的内容完全不清楚。
return this;
CreatePostCommand postCmd = NewPostPage.CreatePost("This is the test post title");
postCmd = postCmd.WithBody("Hi, this is the body");
postCmd.publish();