testing - can you test nested functions in scala? -


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

For example, g () is a way of testing in the code given below:

  def f () = {def G () = "a string!" G () + "A" A "G" says}}    

G F is not visible outside, so I do not have any courage, at least not without reflection

I think the test code G will break the concept of unit testing, anyway, because you should not test the implementation details, but only when testing for public API behavior f fails < Tracking an error in / code> is part of the debugging process.

If the test is g important to you, define g as the (protected) method out of f though It can break your design.

Any other idea has to call g in the original code and then call apply . It will be executed during the trial and if unchanging, then the exception will be raised, which will cause the test to fail. It will also be in regular code, but emphasis (and colleagues) can be removed as a compiler (e.g., see).

Comments