小编Kar*_*lli的帖子

Spock groovy - 如何模拟同一类中的方法?

如何在测试类中mock私有方法和不同类中的方法?

class MyClass {
    private final Retriever<ScoreData> retriever;
    private DataStore<Model> dataStore;
    private String gameName;

    public void MyClass(Retriever<ScoreData> retriever, DataStore<Model> dataStore, String gameName) {
        this.retriever = retriever;
        this.dataStore = dataStore;
        this.gameName = gameName;
    }

    public void process(GameHolder<G> games) {
        // Business Logic
        for (Game<G> game : games){
        Integer score = game.getScore();
        Integer playerId = game.getPlayerId();
        Integer finalScore = getScore(game);
        computeScore(score, finalScore);
        }
    }

    private Integer computeScore(int score, int finalScore) {
        // Runs some business logic and returns O3
        return score + …
Run Code Online (Sandbox Code Playgroud)

java groovy mocking mockito spock

1
推荐指数
1
解决办法
5460
查看次数

标签 统计

groovy ×1

java ×1

mocking ×1

mockito ×1

spock ×1