You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2019/05/22 15:01:01 UTC

[jira] [Commented] (GROOVY-9135) Additional support for @Testable annotation in JUnit5Runner

    [ https://issues.apache.org/jira/browse/GROOVY-9135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16845958#comment-16845958 ] 

Paul King commented on GROOVY-9135:
-----------------------------------

Here are some examples.

jqwik @Example:
{code}
@Grab('net.jqwik:jqwik:1.1.3')
@Grab('org.assertj:assertj-core:3.11.1')
import static org.assertj.core.api.Assertions.*
import org.assertj.core.data.*
import net.jqwik.api.*

class PropertyBasedTests {
    @Example
    void squareRootOf16is4() { 
        assertThat(Math.sqrt(16)).isCloseTo(4.0d, Offset.offset(0.01d));
    }
}
// JUnit5 launcher: passed=1, failed=0, skipped=0, time=207ms
{code}

jqwik @Property:
{code}
@Grab('net.jqwik:jqwik:1.1.3')
import net.jqwik.api.*
//import net.jqwik.api.constraints.*

class PropertyBasedTests {
    @Property
//    @Report(Reporting.GENERATED)
    boolean 'absolute value of all numbers is positive'(@ForAll int anInteger) {
//    boolean 'absolute value of all -ve numbers is positive'(@ForAll @Positive int anInteger) {
//        Math.abs(anInteger) >= 0
//        Math.abs(-anInteger) >= 0
        Math.abs(anInteger) >= 0 || anInteger == Integer.MIN_VALUE
    }

    @Property
//    @Report(Reporting.FALSIFIED)
    void 'size of concatenated string is greater than size of each'(
//    void 'size of concatenated string is greater than or equal to size of each'(
        @ForAll String s1, @ForAll String s2
    ) {
        String conc = s1 + s2
        assert conc.size() >= s1.size()
        assert conc.size() >= s2.size() 
    }

    @Property
    void 'size of concatenated string is sum of size of each'(
        @ForAll String s1, @ForAll String s2
    ) {
        String conc = s1 + s2
        assert conc.size() == s1.size() + s2.size()
    }
}
{code}
which gives:
{noformat}
timestamp = 2019-05-23T00:58:10.177624200, PropertyBasedTests:size of concatenated string is sum of size of each = 
                              |--------------------jqwik--------------------
tries = 1000                  | # of calls to property
checks = 1000                 | # of not rejected calls
generation-mode = RANDOMIZED  | parameters are randomly generated
after-failure = PREVIOUS_SEED | use the previous seed
seed = 212454348596096853     | random seed to reproduce generated values


timestamp = 2019-05-23T00:58:10.203554400, PropertyBasedTests:absolute value of all numbers is positive = 
                              |--------------------jqwik--------------------
tries = 1000                  | # of calls to property
checks = 1000                 | # of not rejected calls
generation-mode = RANDOMIZED  | parameters are randomly generated
after-failure = PREVIOUS_SEED | use the previous seed
seed = 7075331752777813428    | random seed to reproduce generated values


timestamp = 2019-05-23T00:58:10.237463500, PropertyBasedTests:size of concatenated string is greater than size of each = 
                              |--------------------jqwik--------------------
tries = 1000                  | # of calls to property
checks = 1000                 | # of not rejected calls
generation-mode = RANDOMIZED  | parameters are randomly generated
after-failure = PREVIOUS_SEED | use the previous seed
seed = -2728728476853922926   | random seed to reproduce generated values


JUnit5 launcher: passed=3, failed=0, skipped=0, time=288ms
{noformat}
And Spock 2 (SNAPSHOT) using Junit 5.5.0-M1/1.5.0-M1:
{code}
import spock.lang.* 
class AClass extends Specification { 
   def "atest"() { 
     expect: 
     true 
   } 
}
// JUnit5 launcher: passed=1, failed=0, skipped=0, time=52ms
{code}

> Additional support for @Testable annotation in JUnit5Runner
> -----------------------------------------------------------
>
>                 Key: GROOVY-9135
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9135
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Leonard Brünings
>            Assignee: Paul King
>            Priority: Major
>
> There are additional cases which some testing frameworks use, e.g. @Testable might be a meta-annotation. This issue will cover those cases.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)