JUnit ClassRules in Spock

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JUnit ClassRules in Spock

grzesuav
Hi all

I can't find information if @ClassRule is respected bu spock during execution.

I try to write some class rule which can do some @BeforeClass initializations, but I can't make spock to respect it.

I came up with this :


class SputnikWithParametersTest extends Specification {

    @ClassRule
    @Shared
    public static ClassParameters<int[]> PARAMETERS = ClassParameters.withParameters([[2, 2], [-2, 2]])


    static int a;

    static int b;

    @BeforeClass
    void before() {
        int[] parameter = PARAMETERS.getParameter()
        println("Parameters : ${parameter}")
        a = parameter[0]
        b = parameter[1]
    }

    def 'some'() {
        when:
            int abs = Math.abs(a)
        then:
            abs == b
    }

    def 'second'() {
        when:
            int abs = Math.abs(a)
        then:
            abs == b
    }
}

but spock didn't catch Class Rule.


When I change it to normal rule :


class SputnikWithParametersTest extends Specification {

    @Rule
    ClassParameters<int[]> PARAMETERS = ClassParameters.withParameters([[2, 2], [-2, 2]])


    int a;

    int b;

    def 'some'() {
        setup:
            int[] parameter = PARAMETERS.getParameter()
            println("Parameters : ${parameter}")
            a = parameter[0]
            b = parameter[1]
        when:
            int abs = Math.abs(a)
        then:
            abs == b
    }

    def 'second'() {
        setup:
            int[] parameter = PARAMETERS.getParameter()
            println("Parameters : ${parameter}")
            a = parameter[0]
            b = parameter[1]
        when:
            int abs = Math.abs(a)
        then:
            abs == b
    }
}

it started to process rule (so it support normal rules)

Have anyone successfully used Class Rules with Spock ?



Regards,

Grzesiek

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JUnit ClassRules in Spock

grzesuav
Hi,


actually mechanism is working, but I have some issue in my class rule, I need to debug it. Sorry for spamming,


Cheers,

Grzesiek

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JUnit ClassRules in Spock

grzesuav


W dniu wtorek, 12 maja 2015 14:52:08 UTC+2 użytkownik [hidden email] napisał:
Hi,


actually mechanism is working, but I have some issue in my class rule, I need to debug it. Sorry for spamming,


Cheers,

Grzesiek


it seems that help change :
    static int a;

    static int b;

to 

    @Shared
    int a;

    @Shared
    int b;

it is probably of my leak of knowledge in groovy/spock beahvior.


Cheers,

Grzesiek
 

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...