Java - Logback以显示运行状态(已通过/已失败)(Java - Logback to display status of run (passed / failed))
我正在我的Selenium Webdriver项目中使用Logback,我正试图在测试结束时找到一种记录状态(测试通过或失败)的方法,因此在查看日志时您知道哪个测试失败了。
我有一个
afterMethod
,我目前登录“ testGoogleWebsite已完成 ”,但想要“ testGoogleWebsite失败 ”或“ testGoogleWebsite已通过 ”。我的测试:
@Test public void testGoogleWebsite() { openGoogleWebsite(); searchForStackOverflow(); clickOnStackOverflowLink(); } @AfterMethod public void afterMethod(Method method){ LOG.debug(method.getName() + " has finished"); }
我的logback文件:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <property name="DEV_HOME" value="target/Logs" /> <appender name="FILE-AUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${DEV_HOME}/debug.log</file> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <Pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</Pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- rollover daily --> <fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> </appender> <logger name="com.test" level="debug" additivity="false"> <appender-ref ref="FILE-AUDIT" /> </logger> <root level="debug"> <appender-ref ref="FILE-AUDIT" /> </root> </configuration>
I am using Logback in my Selenium Webdriver project and I'm trying to find a way to log the status (whether the test passed or failed) right at the end of the test, so when looking through the logs you know which test has failed.
I've got an
afterMethod
where I currently log "testGoogleWebsite has finished", but want to get "testGoogleWebsite has failed" or "testGoogleWebsite has passed".My Test:
@Test public void testGoogleWebsite() { openGoogleWebsite(); searchForStackOverflow(); clickOnStackOverflowLink(); } @AfterMethod public void afterMethod(Method method){ LOG.debug(method.getName() + " has finished"); }
My logback file:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <property name="DEV_HOME" value="target/Logs" /> <appender name="FILE-AUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${DEV_HOME}/debug.log</file> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <Pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</Pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- rollover daily --> <fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> </appender> <logger name="com.test" level="debug" additivity="false"> <appender-ref ref="FILE-AUDIT" /> </logger> <root level="debug"> <appender-ref ref="FILE-AUDIT" /> </root> </configuration>
原文:https://stackoverflow.com/questions/40514711
最满意答案
您可以使用
RegularExpression
属性:[RegularExpression("^(?!abc$).*$")]
正则表达式是一个负向前瞻(基本上检查字符串不是以
abc
开头,后跟字符串结尾),然后允许任何其他序列。You can use
RegularExpression
attribute for this:[RegularExpression("^(?!abc$).*$")]
The regex is a negative lookahead (basically checking that string does not start with
abc
followed by string end), and then allowing any other sequence.
相关问答
更多-
您可以使用getAnnotation来确定在该字段上是否存在特定的Annotation,它将注记类作为参数: field.getAnnotation( SomeAnnotation.class ); 您可以使用以下方法来验证某个类是否有由给定批注注释的字段: import java.lang.reflect.Field; import javax.validation.constraints.NotNull; import org.junit.Test; import org.springframewor ...
-
这个性质: [System.Web.Mvc.HiddenInput(DisplayValue = false)] public int Id { get; set; } 将被渲染为ie 当使用Html.EditorForModel()或Html.EditorFor(m => m.Id) This property: [System.Web.Mvc.HiddenInput(DisplayValue = ...
-
刚刚找到答案.. [HiddenInput(DisplayValue = false)]作品,但我不得不补充: using System.Web.Mvc; just found the answer actually.. [HiddenInput(DisplayValue = false)] works but I had to add: using System.Web.Mvc;
-
您可以使用存在的验证规则对其进行验证: $validationRules = ['course_id' => 'exists:course,id']; You can validate it by using the exists validation rule: $validationRules = ['course_id' => 'exists:course,id'];
-
MVC 2数据注释问题(MVC 2 Data annotations problem)[2022-03-27]
在MVC2的开发过程中,他们从输入验证到模型验证,在所有情况下都应该完全验证您的对象。 确保您使用的是最新版本(RTM)。 但是, [Required]仅表示该属性不能为null 。 不幸的是, String.Empty - 这是字符串的默认值 - 不是null ,因此模型验证将传递空字符串。 有关详细信息,请参阅Brad Wilson的这篇文章 。 作为解决方案,您可以使用[RegularExpression("....")]对最小字符串长度和允许的字符施加限制。 Half way through the ... -
至于你尝试的简单正则表达式,你可以使用: ^.{8,}$ 您不希望正向查找(?=)。 请参阅我的描述为什么最后会出现这种情况。 对于简单的字符串长度检查,如果您使用的是asp.net 4.0,则可以使用StringLength length属性: [StringLength(8, MinimumLength=1)] (注意:正如Tommy在评论中指出的那样,你需要一个正则表达式来进行完整的密码检查)。 如果你正在寻找更复杂的密码正则表达式,那么我建议你看看汤米的答案, 在这里和这里开始。 为什么(?=) ...
-
帮助注释(Help with annotations)[2023-04-10]
我看到附加多个注释的方式是使用容器注释,然后将项指定为数组。 @Retention(RetentionPolicy.RUNTIME) public @interface Menu { String name(); String[] children(); } @Retention(RetentionPolicy.RUNTIME) public @interface MenuBar { Menu[] value(); } @Retention(RetentionPolicy.RUN ... -
您可以使用RegularExpression属性: [RegularExpression("^(?!abc$).*$")] 正则表达式是一个负向前瞻(基本上检查字符串不是以abc开头,后跟字符串结尾),然后允许任何其他序列。 You can use RegularExpression attribute for this: [RegularExpression("^(?!abc$).*$")] The regex is a negative lookahead (basically checking t ...
-
是否可以定义MVC数据注释不允许的字符串?(Is it possible to define strings that aren't allowed for MVC Data Annotations?)[2022-02-19]
当然,您可以创建自定义属性来执行此操作。 它可以简单地检查名称的黑名单,并根据结果返回true或false。 创建一个继承自ValidationAttribute的类可能就是这样。 例 public class NameAttribute : ValidationAttribute { public override bool IsValid(object value) { // do your blacklist logic here. ... -
常量不能在运行时更改。 事实上,它们的值已经解析,并且在编译过程中每次出现的常量都会被其值替换。 这就是为什么你要做的事情是不可能的。 我想说这里最简单的方法是让Eid成为一个只读字段: private readonly int Eid; public QuoteDimension(int eid) { Eid = eid; } public QuoteDimension(int eid) : this(0) { } 并在QuoteDimension类中实现IValidatableObject ...