在将Spring版本更新为2.6.4之后,当旧的版本2.1.7运行良好时,测试用例中出现了错误
@Test
fun `Should include id in all outbound requests`() {
(authenticationSource as TestAuthenticationSource).setCoordinatorToken()
val request = PersonSearch().apply {
firstName = “Xyz”
lastName = “Abc”
}
val oid = UUID
使用AssertJ,我可以检查Map是否具有满足特定Consumer的引用值的键
@AllArgsConstructor
@Getter
public static class User {
private Long id;
private String name;
}
@Test
public void x() {
Map<String, User> map = new HashMap<>();
map.put("key", new User(123, "Random Hacker"));
As
我在Java8上的Eclipse3.5.2中探索Condition类的用法时遇到了这个问题。我可以为泛型列表创建一个Condition实例,但是当我尝试使用它时,我在AssertJ中得到了错误消息:
Condition<List<MyBean>> listCond =
new Condition<>(list -> true, "test"); // OK
this.assertThat(myList).has(listCond); // DOES NOT COMPILE
我得到的错误消息是:
The method h
我用断言。除其他外,它还具有assertThat(int)和assertThat(Object)功能。我想添加我自己的功能
fun <T> assertThat(flux: Flux<T>) = assertThat(flux.toStream())
但似乎我很难使用它。当我在测试类MyTest之外声明函数时,测试中的函数调用绑定到assertThat(Object)而不是assertThat(Flux)。
import org.assertj.core.api.Assertions.assertThat
//<----------- if declared h
在集成测试中,我有一种奇怪的行为,在使用注释SpringBootTest和自动装配服务时捕获日志。我使用来捕获日志。
使用特定的设置,我无法捕获日志,我无法理解为什么会发生这种情况。我不确定我是否遗漏了弹簧引导测试配置中的某些内容,或者它是否是其他什么东西。
因此,让我们假设存在一个FooService:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class FooService {
p
我想检查两个列表(比方说,ArrayLists)是否具有完全相同的实例类(基于预期的列表)。要做到这一点,我已经构建了下一个方法,但我想知道是否还有另一种使用某些库的奇特方法,比如assertJ。
private void assertConcreteTypes(List actual, List expected) {
for (int i = 0; i < actual.size(); i++){
assertThat(actual.get(i)).isExactlyInstanceOf(expected.get(i).getClass
当我尝试执行单元测试时,我得到了NoSuchMethodError on AssertJ。make步骤工作得很好,当导航到assertThat()的实现时,它工作得很好。
模块依赖关系显示,我使用的是org.assertj:assertj-code:1.2.0,因为我在我的build.gradle中定义为编译依赖项(是的,编译而不是测试)。单元测试驻留在我模块的主类路径中,因为它是一个集成测试,所以这是有意的。iml文件包含:
我的示例测试是:
import org.assertj.core.api.Assertions;
import org.junit.Test;
public
我有:
@Test
public void testSomethingInFooFunction() {
//given
Something parameter = new Something();
//when
List<Object> result = foo(parameter);
//then
// not working
assertThat(result).isEmpty().or().containsOnly(something());
assertThat(result).is(v -> v.i
具有POJO,如:
public class ClientWebRequest {
private URI uri;
private HttpMethod httpMethod;
private final Header header;
private final Body body;
public ClientWebRequest(){
header = new Header();
body = new Body();
}
//getters and setters
}
关于JUnit与Asse
我正在寻找番石榴真理等价物AssertJ usingElementComparatorIgnoringFields忽略一些字段。
例:
data class CalendarEntity(
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
var name: String
)
Truth.assertThat(currentCalendars).containsExactlyElementsIn(expectedCalendars) // Here I want to ignore the id field
我想检查测试下的集合是否包含任何以特定字符串结尾的元素。 对于Hamcrest,它可能是这样的: assertThat("Contains an element ending with 'xyz'",
myCollection, hasItems(endsWith("xyz"))); 如何对AssertJ做同样的事情呢?
这里有一个示例方法,解释了我想要做的事情。
public void myMethod(Method m){
report = new ExtentReports("filename");
test = report.startTest("testName");
String actual = "sssssss";
String expected = "xxxxxxxx";
// what I can do with AssertJ id have a nice readable t
我正在使用AssertJ库在测试中执行断言。在这种情况下,我想测试列表中的每个Date对象是否都在其他日期之后。
因此,我显然可以做到以下几点:
Date dateOne = new Date(someTimestamp);
Date dateTwo = new Date(otherTimestamp);
Assertions.assertThat(dateOne).isAfter(dateTwo);
对此没有疑问。
但是,如果我想测试列表中的每个元素,以确保所有元素都是在给定日期之后,该怎么办?
Date dateOne = new Date(someTimestamp);
Date da