How to Write Test Codes for C# ESS Projects
Version: All
ESS (Elliott SPS Services) is a cloud hosting service that translates incoming EDI XML files (i.e., 850) from SPS Commerce to the Elliott Sales Order Import format (fixed length ASCII), and translates the outgoing Elliott sales order export files (fixed length ASCII) to SPS Commerce EDI XML files (e.g., 810, 856, 855).
ESS is written in C#. The following document illustrates an example of how we write test codes for any feature we add for ESS. In this example, we added a partner config flag, DefaultOrerFrghtPayCode, to set the default value for ORDER_FRGHT_PAY_CODE. The default is blank. But you can use this flag, for example, to set the default value of ORDER_FRGHT_PAY_CODE to "H" so the incoming sales order for a particular trading partner will be put on hold by default and require a "release" in Elliott in order to print the pick ticket. See example codes below:
The codes above are very simple. But we do not just assume that it will work. To make sure it will function as intended, we will write test codes to confirm. The test codes will be executed automatically upon the release of a new revision. The test codes must pass before the release process will push it to production. In addition, if there are any changes in other areas that somehow affect the result here, the test codes will catch those too. Therefore, this is a great QC process for source code changes and releases.
To write test codes for these few lines of code, we can right click on the source code area. In the popup menu, we choose, "Create Unit Test." See sample screen below:
In the popup dialog "Create Unit Tests," choose "xUnit.net 2.0" for Test Framework. Choose "Ess.UnitTests" for Test Project. Choose default for the rest. See sample screen below:
If the test source file does not exist, it will be created automatically. In this case, the original source code file name is "HeaderFieldMapper.cs." So the automatically created test codes file name will be "HeaderFieldMapperTests.cs." See sample screen below:
If the test source file already exists, that test source file will be brought up automatically. You will then add your additional test logic to that source file.
The following is a sample implemented source code of the example feature. The function is descriptive to indicate the intention of the test. In this case, we wrote two functions: one to test when the partner config flag DefaultOrderFrghtPayCode = "H," and one to test when the flag is not set. See sample screen below:
To run this test, you can move your cursor to the test function you just wrote and use the shortcut key Ctl-R, then Ctl-T to run the test for that function only. As you can see in the example following, only this test function was executed:
You can also test all written tests of this project by choosing "Run" -> "All Tests." See sample screen below. This will take longer to run, but it will ensure the changes you made will not bring unintentional consequences to other areas:
EMK