【发布时间】:2018-08-28 17:32:41
【问题描述】:
如何打印放心日志和 log4j 日志 log.info 和/或 system.out.println 语句是否也在 log4j 文件中?当前代码 下面只打印出放心的日志,但很难阅读 它属于哪个测试用例以及来自哪个类。我希望 有人可以告诉我如何添加该信息并打印出来 我要添加的文本 cmets 将放心日志划分为 测试和上课。感谢您的帮助。
package com.students.loggingexamples;
import com.student.base.TestBase;
import static io.restassured.RestAssured.given;
import java.io.FileNotFoundException;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.junit.Test;
public class LoggingResponseValues extends TestBase{
private static Logger log =
LogManager.getLogger(LoggingResponseValues.class.getName());
/*
* This test will print out the response body.
*/
@Test
public void test003() {
log.info("---Printing Response Body---");
given()
.param("programme", "Computer Science")
.param("limit", 1)
.when()
.get("/list")
.then()
.log()
.body()
.statusCode(200);
}
/*
* This test will print out the response in case of an error.
*/
@Test
public void test004() throws FileNotFoundException {
log.info("---Printing Response Body In Case of An Error---");
given()
.param("programme", "Computer Science")
.param("limit", -1)
.when()
.get("/list")
.then()
.log()
.ifError();
}
}
public class TestBase {
@BeforeClass
public static void init() throws FileNotFoundException {
RestAssured.baseURI="http://localhost";
RestAssured.port=8080;
RestAssured.basePath="/student";
//Prints out the rest-assured logs into file
PrintStream fileOutPutStream = new PrintStream(new
File("C:\\EclipseProjects\\students-application\\logs\\main.log"));
RestAssured.config = RestAssured.config().logConfig(new
LogConfig().defaultStream(fileOutPutStream));
}
}
【问题讨论】:
标签: log4j rest-assured