I am new to elixir and trying to learn some of it's features including the testing library ExUnit, but I am having some trouble understanding the concept of how to write and setup a test for a particular function and if I am going in the correct direction.
For example, to test if a list is ordered after getting data fr om a CSV file, would I need to actually call the function I wrote that does this or just provide a mock list of unordered data?
//Module function that parses the CSV file
def parse_csv do
@csv_path
|> Path.expand(__DIR__)
|> File.stream!
|> CSV.decode
|> CSV_MODULE.prioritize_claims
end
Do I need to actually import that module function into my test file and then actually invoke it or do I just provide a sample test list that is unordered then pass the list to the function that is suppose to sort it.
If you write a helper function to do just that and call it with the output you get from your parse_csv function you can and should just test it directly with the possible outputs you expect to get from that function.
If you want to test everything together it’s also a good option to have a sample CSV file, or even multiple to test that everything works as expected.