Skip to content

Instantly share code, notes, and snippets.

@multidis
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save multidis/5f5168c9f75f3b831b0f to your computer and use it in GitHub Desktop.
Save multidis/5f5168c9f75f3b831b0f to your computer and use it in GitHub Desktop.
TDD workflow in Julia language (NOTE: mostly personal preferences).

Structure, naming, setup

In the project directory, open in LightTable:

  • ModuleName.jl with functions under development (Capitalize jl-file names containing modules, match file and module names)
  • usingfile.jl that does include("ModuleName.jl") (which allows reloading without Julia restart, see FAQ)

In the ./test/ sub-directory, put the file with FactCheck tests for ModuleName functions: collect all tests into one file named modulename.jl, i.e. the same as source but without capitalization and residing in the testing sub-directory. Open it in LightTable as well.

Test-driven development steps

  1. Open a terminal with interactive Julia REPL in the project directory
  2. using FactCheck
  3. include("ModuleName.jl"); include("./test/modulename.jl")

Proceed with the TDD write test, fail, edit code, pass workflow re-running the last steps above after code edits. IMPORTANT: always remember to reload the module after edits, include("ModuleName.jl") (hence 2 commands are chained in step 3 above). Otherwise tests will apply to the previously loaded version. Seems obvious but easy to skip my mistake in practice.

## what the module does
module ModuleName
using Something
export myfunc1, myfunc2
function myfunc1()
1
end
function myfunc2()
2
end
end # module
## what we are trying to accomplish
include("ModuleName.jl")
using ModuleName
myfunc1()
myfunc2()
## resides in ./test/ sub-directory
facts("Scope A") do
@fact ModuleName.myfunc1() => 1
end
facts("Scope B") do
@fact ModuleName.myfunc2() => 2
end
# group fact checks in top-level scopes and sub-level contexts;
# good examples:
# https://github.com/zachallaun/FactCheck.jl/blob/master/src/example_factcheck.jl
# https://github.com/JuliaStats/TimeSeries.jl/blob/master/test/timearray.jl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment