Questions tagged [assertthat]
27 questions
72
votes
2 answers
How do I use Hamcrest with JUnit 5 when JUnit 5 doesn't have an assertThat() function?
To use Hamcrest with JUnit 4 we use an assertThat() function. However, JUnit 5 is no longer going to have an assertThat() function. How do I use Hamcrest without an assertThat()?

Max
- 2,036
- 2
- 18
- 27
10
votes
2 answers
How to use the isA-Matcher
I have a certain method that delivers a Restriction-object (where Restriction is an interface). And since its implementation is already testet, I just want to test if my method actually delivers a RestrictionImpl-object.
I saw that there are…

danielspaniol
- 2,228
- 21
- 38
6
votes
4 answers
Warnings instead of errors from assert_that()?
I'm using R's assertthat package and am wanting to (temporarily) output a warning instead of an error on assertion failure. What's the easiest way to do that with the assertthat package?
I realize that wanting warnings instead of errors kind of goes…

Eric
- 829
- 1
- 8
- 15
4
votes
1 answer
Best practice for match arguments that depends on others
I'm new to R functions and so far i would check arguments like:
foo = function(state = c("solid", "liquid"),
thing = c("rock", "water")) {
state = match.arg(state)
thing = match.arg(thing)
if (state == "solid" & thing ==…

Alberson Miranda
- 1,248
- 7
- 25
4
votes
1 answer
Storing input value to check wether postcondition holds true when applying Design-by-Contract
I make use of the assertthat package quite often to check postconditions in functions. When reading more about the idea of Design by Contract I stumbled upon the idea to make checks of output in comparison to input values.
The most simple example is…

symbolrush
- 7,123
- 1
- 39
- 67
2
votes
1 answer
Hamcrest Pattern Assert 2 Properties of Custom Collection
I have a Java Custom Object collection List with two (2) properties. It is received as a response of Web Service. The object seems like
public class Employee{
public String getName(){ ... }
public String getDesignation(){ ... }
}
I…

Shany
- 43
- 6
2
votes
2 answers
How to use Hamcrest's AssertThat for String[]
So I've been looking around and trying to find a solution to this problem but I'm coming up with either compiler errors or weird expectations or both.
So here we go:
this.mockPersonNode.setProperty("fname",new String[] {"John"});
...unrelated…
user2990134
1
vote
1 answer
assertthat return the message from the current function when called in a nested manner
Let me explain with the help of an example.
I have two functions :
fun1 <- function(x) {
assertthat::assert_that(is.numeric(x), msg = 'Not a number')
x
}
fun2 <- function(x) {
assertthat::assert_that(x > 10, msg = 'Number not greater than…

user16024709
- 151
- 1
- 12
1
vote
0 answers
How to get screenshot for each soft assert failure with AssertJ SoftAssertions
I want to achieve below: -
CustomSoftAssertJ softly = new CustomSoftAssertJ();
softly.assertThat(actual).isEqualTo(expected); // get screen shot on failure
softly.assertThat(actual).isEqualTo(expected); // get screen shot on…

Deepak Arora
- 31
- 6
1
vote
1 answer
The method assertThat(List) is undefined for the type SpringDataOverviewApplicationTestsJava(67108964)
I am trying to follow along with a pluralsight demo course on JPA and the test I just built is throwing an error on the assertThat method and I can't figure out why. I'm sure this is super obvious, but I can't find the solution on here or on the…

TiredFullStacker
- 35
- 4
1
vote
1 answer
Returning an error message other than the last one thrown in R
I have two functions that construct R S3 objects. One object encapsulates the other. When the user passes a bad num argument to fun2() it throws the error assertion in fun2(). I think it would be more informative for the user to see the message in…

Eli Miller
- 86
- 5
1
vote
2 answers
incompatible cucumber json report between karate and cucumber
I am trying to import json results from karate tests into the AssertThat Jira plugin.
Importing works well with cucumber js 5.1.0, but fails using karate 0.9.2
Seems that the problem lies in AssertThat using the Feature's "name" in the json to…

Rsf
- 126
- 1
- 6
1
vote
2 answers
The method is(int) is undefined
I imported using the following:
import static org.junit.Assert.*;
But on the following line:
assertThat(0, is(1));
I get The method is(int) is undefined for the type AppTest.
The name of this method is so common in the English language that I can…

clankill3r
- 9,146
- 20
- 70
- 126
1
vote
0 answers
A collection containing some specific string, but having list of Strings
I've implemented this method:
@FindBy(partialLinkText = "Avocode")
List results;
public List getSearchResults (){
List text = results.stream().map(WebElement::getText).collect(Collectors.toList());
return…

Lijana
- 11
- 2
1
vote
0 answers
Use of environment in validate_that in R
I am trying to write my own test-function (test_if) that returns both the result of the test as well as an optional error message. The function is based on the validate_that function in the assertthat-package.
The test_if function seems to work,…

R learner
- 101
- 7