Unit test private methods in F #

Let, say, a class

type ThisClassIsComplicated () = 
    let calculateSomething a b =
        a + b 

In this case calculateSomething, it is trivial, but if it will be more difficult, it makes sense to verify that the calculations made there are correct.

It might make sense to use a unit testing system to verify that private methods.

My question is: how is unit test private methods in F #?

Some random thoughts:

The selected answer here suggests using an attribute, InternalsVisibleTowhich in any case only applies to internalmethods .

What is the F #-specific route, if any? Is this better in F # design?

let calculateSomething a b = a + b 

type ThisClassIsComplicated () = 
    member this.Calculate a b = calculateSomething a b

Perhaps the area calculateSomethingmay even be narrowed if a nested module .

+4
3

, , , . ,

let myComplicatedOperation input = 
    let calculateSomething a b =
        a + b
    calculateSomething (fst input) (snd input)

currying :

let myComplicatedOperation calculateSomething input =
    calculateSomething (fst input) (snd input)

, , F #. - , , (, F #, let). /.

+4

, / . , - , , .

/ /, ?

type ThisClassIsComplicated () = 
    let calculateSomething a b =
        a + b 

    member private this.TestInstance () = 
        printfn "%A" <| calculateSomething 1 2

    static member Test () = 
        (new ThisClassIsComplicated()).TestInstance()
+3

Source: https://habr.com/ru/post/1532292/


All Articles