Is Assert.Fail() considered bad practice?

前端 未结 14 1144
面向向阳花
面向向阳花 2021-01-31 07:20

I use Assert.Fail a lot when doing TDD. I\'m usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where

14条回答
  •  被撕碎了的回忆
    2021-01-31 07:41

    With the good code I usually do:

    void goodCode() {
         // TODO void goodCode()
         throw new NotSupportedOperationException("void goodCode()");
    }
    

    With the test code I usually do:

    @Test
    void testSomething() {
         // TODO void test Something
         Assert.assert("Some descriptive text about what to test")
    }
    

    If using JUnit, and don't want to get the failure, but the error, then I usually do:

    @Test
    void testSomething() {
         // TODO void test Something
         throw new NotSupportedOperationException("Some descriptive text about what to test")
    }
    

提交回复
热议问题