# Julia Language Unit Testing Writing a Simple Test

## Example

Unit tests are declared in the `test/runtests.jl` file in a package. Typically, this file begins

``````using MyModule
using Base.Test
``````

The basic unit of testing is the `@test` macro. This macro is like an assertion of sorts. Any boolean expression can be tested in the `@test` macro:

``````@test 1 + 1 == 2
@test iseven(10)
@test 9 < 10 || 10 < 9
``````

We can try out the `@test` macro in the REPL:

``````julia> using Base.Test

julia> @test 1 + 1 == 2
Test Passed
Expression: 1 + 1 == 2
Evaluated: 2 == 2

julia> @test 1 + 1 == 3
Test Failed
Expression: 1 + 1 == 3
Evaluated: 2 == 3
ERROR: There was an error during testing
in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at ./test.jl:397
in do_test(::Base.Test.Returned, ::Expr) at ./test.jl:281
``````

The test macro can be used in just about anywhere, such as in loops or functions:

``````# For positive integers, a number's square is at least as large as the number
for i in 1:10
@test i^2 ≥ i
end

# Test that no two of a, b, or c share a prime factor
function check_pairwise_coprime(a, b, c)
@test gcd(a, b) == 1
@test gcd(a, c) == 1
@test gcd(b, c) == 1
end

check_pairwise_coprime(10, 23, 119)
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.80344814,"math_prob":0.52240235,"size":1111,"snap":"2022-40-2023-06","text_gpt3_token_len":367,"char_repetition_ratio":0.1300813,"word_repetition_ratio":0.0591133,"special_character_ratio":0.33753374,"punctuation_ratio":0.1891892,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9913903,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-26T10:36:43Z\",\"WARC-Record-ID\":\"<urn:uuid:8a05011d-db4c-45d4-aec5-dbd3426dd061>\",\"Content-Length\":\"35237\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9fbc65a4-7fbd-4f92-b8c0-9d9f62ea5281>\",\"WARC-Concurrent-To\":\"<urn:uuid:2a02af93-0054-4464-82c0-98a2b1720e04>\",\"WARC-IP-Address\":\"40.83.160.29\",\"WARC-Target-URI\":\"https://riptutorial.com/julia-lang/example/19976/writing-a-simple-test\",\"WARC-Payload-Digest\":\"sha1:245HACOJA2PIWS6QAVRVMPLFMPU2BZIJ\",\"WARC-Block-Digest\":\"sha1:2AB5HDIHEDS54GPJFSQAWMBGCQQ5PTWF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030334855.91_warc_CC-MAIN-20220926082131-20220926112131-00788.warc.gz\"}"}