上下文
我正在使用带有TestNG Eclipse插件的Spring Tools Suite / Eclipse中的TestNG编写单元测试。作为这些测试之一,我正在测试是否使用slf4j-test库(https://projects.lidalia.org.uk/slf4j-test/)创建了正确的日志输出
遇到的兼容性错误是:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/C:/Users/****/.m2/repository/ch/qos/logback/logback-
classic/1.2.3/logback-classic-
1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/****/.m2/repository/uk/org/lidalia/slf4j-
test/1.1.0/slf4j-test-1.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
SLF4J: Actual binding is of type
[ch.qos.logback.classic.util.ContextSelectorStaticBinder]
为了使用该库,由于与slf4j-test库存在已知的兼容性问题,因此在运行测试时需要排除回退。为此,我将以下内容添加到了pom中:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>ch.qos.logback:logback-classic</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
问题
当我运行“ mvn测试”时,所有测试运行正常,排除工作按预期进行。但是,当我想使用TestNG Eclipse插件运行单个测试(右键单击测试类->以-> TestNG Test身份运行)以便可以在IDE中查看测试结果和覆盖范围时,由于兼容性,测试会中断库之间的问题。
问题
当我想使用TestNG插件单独运行这些测试时,如何从类路径中排除这种依赖关系?