Skip to content
Discussion options

You must be logged in to vote

@LPenny-github

你好 😊

你有把 LeetCode 給的 3 組範例的「 setup (建置測試資料) 」的部分寫得很好,最後的「 Assert (驗證) 」的部分可以改成以下這樣:

    public void LeetCodeExample1()
    {
        // ...

        Assert.Equal(true, new LinkedListCycle().HasCycle(node1));
    }

    [Fact]
    public void LeetCodeExample2()
    {
        // ...

        Assert.Equal(true, new LinkedListCycle().HasCycle(node1));
    }
    [Fact]
    public void LeetCodeExample3()
    {
        // ...

        Assert.Equal(false, new LinkedListCycle().HasCycle(node1));
    }

就這題的情形來說,「選擇具有代表性的測試案例,直接 hard-code 期待值,與 實際值 比對」是比較適當的作法。


比較完整的觀念可以參考 https://martinfowler.com/articles/mocksArentStubs.html

  • Dummy objects are passed around but never actually used…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by LPenny-github
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants