小编use*_*730的帖子

我如何 JUnit 测试构造函数?

此测试运行但失败。不知道为什么?有一个长度为 1 的 Submarine 类。

@Test   
public void testShipConstructor() {
    assertTrue(Submarine.length == 1);      
}
Run Code Online (Sandbox Code Playgroud)

这是该类的代码:

public abstract class Ship {

    private int size;
    public static int length;

    protected Ship(int size, String type, String shortForm) {
        this.size = size;
        this.setType(type);
        this.shortForm = shortForm;
    }

    public static void setLength(int length) {
    }

    public int getLength() {
        return length;
    }

    int getSize() {
        return size;
    }
}

public class Submarine extends Ship {

    private final static int SIZE = 1;

    /**
     * * …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing

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

标签 统计

java ×1

junit ×1

unit-testing ×1