Why can test private methods/fields in Spock without problems?

后端 未结 2 1510
Happy的楠姐
Happy的楠姐 2021-02-10 06:28
package com.example.dev;
public class AClass {
 private Integer a =10;
...//other code
}

and when I try to access a in my Spock method:



        
2条回答
  •  灰色年华
    2021-02-10 06:30

    Spock isn't guilty, it's groovy itself, see: Private method in groovy is not private.

    While it's possible to refer to private members of class, it's definitely not a good practice.

提交回复
热议问题