bug message reminder

When adressing a model crash or bug, please remember to include an entire model setup in your post that reproduces the crash or exposes the bug. Also add the XBlog.txt file. This is necessary information for people that are trying to help you. Including your model setup can be achieved by adding the zipped run directory (excluding output) as an attachment to the post.

Forum

How to write unit tests

Pieter van Geer, modified 7 Years ago.

How to write unit tests

Swell Posts: 176 Join Date: 1/5/11 Recent Posts
With the recent restructuring of the XBeach source code (see this link), a unit testing framework was included. Until this moment the unit tests are only run as a post build action of the test project (xbeachlibrary_test). In the near future we hope to introduce an automated testing environment that runs all tests and publishes the results each time a change is committed to the trunk of the repository. This post describes what you can test and how to add tests.

How are these unit tests different from the tests in the XBeach skillbed?
The XBeach skillbed is meant to run complete XBeach simulations. The results of these simulations can help us judge whether the basic functionality expected by the user is still present. These types of simulations can be seen as acceptance tests, which need to be run before using the compiled code in our daily work.
The unit test framework offers the ability to test individual functions or subroutines. By doing so, functionality of thi piece of the code becomes clear to other developers. Whenever a developer decides to alter functionality of a small piece of the code in order to get his/her section working, he or she can run the unit tests to see whether the needed functionality somewhere else in the code did not break with his/her change. This can save a lot of time that is currently spent in finding the reason why results of a complete simultation change badly at one point after changing something small at a completely different part of the code.

What parts of XBeach can we test with the unit test framework?
The test project references the xbeachlibrary project. Since this project is a .lib, it is possible to individually test all functions and subroutines in the library project.

How to add your own unit tests
Adding a test involves the following steps
  • Add test file. Add a file to the xbeachlibrary_test project in the same dir and with the same name (extended with _test) as the file that contains the function or subroutines to be tested.
  • Write test code. The newly created test file should reference ftnunit and define a general subroutine that calls all tests in that file (also defined as subroutines). The call to the test should be as follows:

    call test( fileNameTestOne,     "Specify Name" )


    The test file will look as follows:


    module filename_tests

        use ftnunit
    !   Add other usages

        implicit none

    contains

    ! Run all tests for filename
    subroutine allIFileNameTests

        call test( fileNameTestOne,     "First test" )
       
    end subroutine allIFileNameTests

    subroutine fileNameTestOne
    ! define test code here. This should include a call to the function that should be tested

    end subroutine fileNameTestOne


    See interp_test for an example.
  • Include test(s) in main test program. Add a statement in the main test program ("run_xbeach_tests.F90") that runs all tests in the newly created testfile. The body of the program contains a call to runtests_init and one to runtests_final. To include the unit tests in the main program, include a call to the general subroutines in the new test file (that runs all tests in that file):


        call runtests_init

        ! Add your test file here
        call runtests( allIFileNameTests )
       
        call runtests_final


    You can have a look at other tests (interp_test) to see how it works.
JC
Jennifer Charles, modified 22 Days ago.

RE: How to write unit tests

Capillary Posts: 5 Join Date: 12/25/19 Recent Posts
The point of unit testing as I understand it is to make small units, that are easily tested. Kings Cross Self Storage
AK
Abdul Kaleem, modified 10 Days ago.

RE: How to write unit tests

Capillary Posts: 1 Join Date: 1/7/20 Recent Posts
Many years ago, I read the blog that is discussing the unit tests there was too small and I do not get the specific information because I was needed for my website student assignment help who work for the students. Now, Suddenly I see this post that briefly discusses the unit tests and also discussing the whole method. It is really important to me and now I will use it in my work.
SA
Sheikh Alya, modified 6 Hours ago.

RE: How to write unit tests

Capillary Posts: 1 Join Date: 1/17/20 Recent Posts
These directions are signifying effective for us when we learn how unit test working step by step for quality assurance of the project. Your mentioned coding is really worked I try it for my final year project unit testing. As a student of Software Engineering, I ask assistance from Assignment Assistance | Assignmenthelpuae.ae website and finally my final year project is done with shining grade.