can you test nested functions in scala?

后端 未结 2 777
遥遥无期
遥遥无期 2021-02-14 10:00

Is there any way to test a nested function (ideally with ScalaTest)?

For example, is there a way to test g() in the below code:

def f() = {
         


        
2条回答
  •  余生分开走
    2021-02-14 10:42

    You could make method private[package-name] - still breaks design a bit, but keeps it private instead of protected.

    Generally I agree with the fact that one should not test private methods, but if you are maintaining poorly written code...

    private[example] def g() = "a string!"
    
    def f() = {
      g() + "– says g"
    }
    

    Now test in same package (example) could test g()

提交回复
热议问题