首页 \ 问答 \ Java - Logback以显示运行状态(已通过/已失败)(Java - Logback to display status of run (passed / failed))

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
更新时间:2023-07-16 14:07

最满意答案

您可以使用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'];
  • 在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在评论中指出的那样,你需要一个正则表达式来进行完整的密码检查)。 如果你正在寻找更复杂的密码正则表达式,那么我建议你看看汤米的答案, 在这里和这里开始。 为什么(?=) ...
  • 我看到附加多个注释的方式是使用容器注释,然后将项指定为数组。 @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 ...
  • 当然,您可以创建自定义属性来执行此操作。 它可以简单地检查名称的黑名单,并根据结果返回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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。