dakusui / thincrest Goto Github PK
View Code? Open in Web Editor NEWYet another assertion library
Home Page: https://dakusui.github.io/thincrest/
License: Apache License 2.0
Yet another assertion library
Home Page: https://dakusui.github.io/thincrest/
License: Apache License 2.0
It is pointless and just introduces 'false-passing' risks.
Use opentest4j instead.
Implement requireThat
and assumeThat
which throw RequirementUnsatisfiedException
(Crest's custom) and AssumptionViolatedException(org.junit)
respectively.
requireThat
will be used when a test code finds a certain requirement to exercise test is not satisfied during fixture preparation.
assumeThat
will be used in the same way as it is in @Theories
, where a certain constraint for input parameter values is found unsatisfied and the test case itself is not valid.
Improve method selecting strategy so that it can handle overloaded methods.
At least we should prefer narrowest possible one among matching ones.
Make it look like following to be more intuitive.
-- when x=<org.junit.runner.Result@77cd7a0>; then and:[
** @wasSuccessful[]->castTo[Boolean](x) isFalse was not met because @wasSuccessful[]->castTo[Boolean](x)=<true>
-- @getRunCount[]->castTo[Integer](x) equalTo[10]
-- @getIgnoreCount[]->castTo[Integer](x) equalTo[0]
-- @getFailureCount[]->castTo[Integer](x) equalTo[0]
--]->false
instead of
** @wasSuccessful[]->castTo[Boolean](x) isFalse was false because
Expose function
and predicate
methods, which creates printable (, returning meaningful string on toString
call) Function
and Predicate
objects.
MissingFormatArgumentException
is thrown if a value to be printed through thincrest
contains any format specifier such as %s
.
Support assertThrows
thincrest
currently has its own precondition checking mechanism, where functions and predicates created from lambdas are printed in a human readable way.
That is, a following method will throw,
void greeting(String in) {
String var = requireArgument(in, isEmptyOrNullString().negate());
System.out.println(var);
}
An illegal argument when in
is an empty string ""
.
java.lang.IllegalArgumentException: value:"" violated precondition:value !isEmptyOrNullString
at com.github.dakusui.pcond.Preconditions.lambda$illegalArgument$3(Preconditions.java:59)
at com.github.dakusui.pcond.Preconditions.require(Preconditions.java:21)
This component is useful for other java applications.
And it should become an independent library, which is called pcond
(printable preconditions).
Right now thincrest does not have a feature to make sure a container (List or String) has given pieces in it in the order they are given.
For instance, sometimes we want to make sure a string has substrings "abc", "def", and "xyz", but anything else can appear in between them.
XabcYdefZxyz
Although you can write a regular expression that matches and only matches such strings, it will be error prone and it produces mismatch explanation difficult to understand.
junit.framework.ComparisonFailure: Element:equalTo[XYZ] was not found expected:<...alTo[XYZ]] isNotNull[]> but was:<...alTo[XYZ]] isNotNull[ failed with junit.framework.AssertionFailedError(Element:equalTo[XYZ] was not found)
x=<("Z","abc","Z"...;7)>:ArrayList
x->after[equalTo[abc]]->after[equalTo[def]]->after[equalTo[XYZ]] isNotNull
| | |
| | +-junit.framework.AssertionFailedError(Element:equalTo[XYZ] was not found)
| |
| +----------------------<("Z","xyz","Z")>:RandomAccessSubList
|
+-------------------------------------------<("Z","def","Z"...;5)>:RandomAccessSubList
It will be convenient if we have a feature where mismatch explanation output above is printed when following test fails.
List<String> targetContainer = asList("Z", "abc", "Z", "def", "Z", "xyz", "Z");
assertThat(
targetContainer,
asListOf(
String.class,
sublistAfterElement("abc").afterElement("def").afterElement("XYZ").$()
).isNotNull().$());
Checking elements in a collection is awkward
(this is a placeholder ticket)
Support static call by 'Call' mechanism.
call("toString").andThenCallStatic(Objects.class, "toString", Call.THIS).$()
callStatic(Objects.class, "toString", Call.THIS).andThen("contains", "hello").$()
call("toString").andThen((String s) -> s.contains("hello")).$()
Right now, a mutator seems not to be called when no checker is set.
This potentially causes 'false-passing' if a user relies on a mutator which should fail when expectation is not met.
Make output format more natural Java-like such as following.
x.append("hello").append("world").toString() @equalTo[HelloWorld] was not met because x.append("hello").append("world").toString()="helloworld"
x=<>:StringBuilder
x.append("hello").append("world").toString() @equalTo[HelloWorld]
| | |
| | +-"helloworld"
| |
| +------------<helloworld>:StringBuilder
|
+----------------------------<hello>:StringBuilder
This issue will be done as a part of Issue #29.
Error message printed on failure in matcher execution is not descriptive.
This happens when a matcher inside AllOf
fails.
When a method like following is run,
@Test
public void givenNoSuchMethodAtFirstCallInsideAllOf$when$then() {
Crest.assertThat(
new Sut(),
Crest.allOf(
Crest.asString(call("noSuchMethod").$()).containsString("hello").$()
)
);
}
Expectation string and actual string will become like this
[and:[
@noSuchMethod[](x) containsString[hello]
]]
[when x=<com.github.dakusui.crest.bugfixes.Issue19Test$Sut@77556fd
While expectation string should be more descriptive such as
when x=<com.github.dakusui.crest.bugfixes.Issue19Test$Sut@368239c8>; then and:[
@noSuchMethod[](x)->@toString[](x) containsString[hello] failed with java.lang.RuntimeException(Method matching 'noSuchMethod[]' was not found in com.github.dakusui.crest.bugfixes.Issue19Test.Sut.(CAUTION: This method doesn't try to cast or unbox arguments to find a method))]
]->false
A place holder ticket for document improvement.
(a place holder ticket for code clean up)
A placeholder ticket for minor improvement in failure messages.
Introduce 'strict' mode for 'call' mechanism.
TestSkippedException
should be thrown when an assumption is violated instead of TestAbortedException
.
As of now (Jan/9/2021), unfortunately, both of them are treated as a test failure by IntelliJ.
Maybe there are such more tools that treat them as a test failures instead of ignoring.
The desired behavior is to make the test running tool ignore the test case which throw an exception from assumeThat
method.
Message shown on failure due to check(Function,Predicate) method is less than informative it can be.
When we use call("methodName", arg1, arg2).andThen("method2").$()
method call chain, results of each call can be printed as follows.
ACTUAL:@toUpperCase[]->@substring[2]->@charAt[1](@toLowerCase[](x)) equalTo[z] was not met because @toLowerCase[](x)="world"
@toUpperCase[](y)="WORLD"
@toUpperCase[]->@substring[2](y)="RLD"
@toUpperCase[]->@substring[2]->@charAt[1](y)="L"
EXPECTED: @toUpperCase[]->@substring[2]->@charAt[1](@toLowerCase[](x)) equalTo[z]
Above is an example for this code fragment.
assertThat(
"WORLD",
asString("toLowerCase").check(
call("toUpperCase").andThen("substring", 2).andThen("charAt", 1).$(),
equalTo('z')
).$())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.