测试类中的字段定义

时间:2016-01-25 11:21:42

标签: java static field final

考虑以下测试类:

public class MyTest extends extends EasyMockSupport {

    private static TestobjectFactory testobjectFactory = new TestobjectFactory();
    private static final Date DATE = testobjectFactory.createDate(2013, 0, 13, 01, 02, 03);
    private static final String CSV = "einCsv";

    @TestSubject
    private ClassToBeTested classUnderTest = new ClassToBeTested();

    @Mock
    private ClassToBeMocked myMock;

    @After
    public void tearDown() {
        verifyAll();
    }

    @Test
    public void myTest() throws Exception {
        replayAll();

        String outcome = classUnderTest.someMethod("", DATE);

        assertThat(outcome, is(""));
    }

    @Test
    public void anotherTest() throws Exception {
        expect(myMock.mockedMethod((String[]) anyObject())).andReturn(testobjectFactory.foo());

        replayAll();

        String outcome = classUnderTest.someMethod(CSV, DATE);

        assertTrue(outcome.contains("abc"));
    }

}

问题:

  • 为什么要定义CSV(或DATE)静态最终版?将它定义为最终我同意,因为它是不变的。但为什么要静电?

  • 哪些字段是大写的? 私人静态决赛MY_FIELD; 私人决赛MY_FIELD; 私人静态MY_FIELD;

  • 使用静态TestobjectFactory不是更好吗?

编辑:

我之前已经看过可能重复的帖子了。但是我写的问题在那里没有答案。

0 个答案:

没有答案