Coder Social home page Coder Social logo

thincrest's People

Contributors

dakusui avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

thincrest's Issues

Implement 'requireThat' and 'assumeThat'

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 mechanism

Improve method selecting strategy so that it can handle overloaded methods.
At least we should prefer narrowest possible one among matching ones.

Improve message

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 

Separate precondition checking mechanism from thincrest

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).

Implement 'inOrder' feature

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().$());

Support static call by 'Call' mechanism

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")).$()

Make output format more natural Java-like

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

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

TestSkippedException should be thrown when an assumption is violated.

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 looks poor.

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')
          ).$())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.