Arrhenius.jl icon indicating copy to clipboard operation
Arrhenius.jl copied to clipboard

Add Unit Testing for development

Open jiweiqi opened this issue 3 years ago • 3 comments

As the package becomes more and more complex, it is important to adopt unit testing. We can following the example of RMS.jl at https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl/blob/ac2a3bd88504b86d5bc60dedc09533839a9c9cbb/src/Calculators/TestThermo.jl#L1-L60.

Some thoughts:

  • [ ] We could put the test files inside the src folder, with a consistent prefix, so that one can easily spot the actual source file.
  • [ ] We can test the functions against Cantera via PyCall. This should work well for most of the functionality.
  • [ ] @test Cps ≈ Cpexplist rtol=1e-3 where 1e-3 is a good default value for tolerance.

jiweiqi avatar May 08 '21 00:05 jiweiqi

That sound like a good ideal. I can add that for the thermo interface.

I think the naming "test_<srcFile>.jl" sounds great. I also agree, that we can test a lot against Cantera. But could you explain, why you would put the test files in the source folder? I would prefer those test files either in the toplevel test dir (e.g. test/test_Thermo.jl) or in a separate folder in the src directory (src/tests/test_Thermo.jl) as I fear, that the src dir becomes cluttered over time. I also find it conceptually odd to place things which are not actually src files in the src toplevel. But maybe I am just unaware of some advantages of the shared folder (especially if they are unique to Julia). In that case please let me know :).

TJP-Karpowski avatar May 08 '21 10:05 TJP-Karpowski

Hi @TJP-Karpowski , I agree with you that we should make the top level of src being clean. Indeed, putting them into either ./test/ or ./src/test is a good idea.

As for the current test files, which are put at the level of src, the reason is that I haven't figured out a good pipeline for debugging code during the development phase. As you probably know, if I import Arrhenius.jl via using Arrhenius, every time I change the source code, I will have to restart the Julia terminal. Instead, I currently import Arrhenius.jl by directly executing the module file as done in https://github.com/DENG-MIT/Arrhenius.jl/blob/3f7700709ad1092291c9d5e3d108f233f845a696/src/_transport_test.jl#L5-L43. I feel this is not a good way to do it. But at the current time being, I haven't tried other approaches.

Noting that, I have to call Arrhenius.R to access the member of the Arrhenius module. This is different from the standard test file, like https://github.com/DENG-MIT/Arrhenius.jl/blob/3f7700709ad1092291c9d5e3d108f233f845a696/test/runtests.jl#L1-L38.

jiweiqi avatar May 09 '21 03:05 jiweiqi

I had the same problem with the Julia restart, luckily we are not the first to have that issue. You can use the revise package: https://timholy.github.io/Revise.jl/stable/ . Just call using Revise before using Arrhenius and then revise will check for changes to the source files and will apply those changes in the running session :).

TJP-Karpowski avatar May 09 '21 11:05 TJP-Karpowski