The case for one test and one learn

The average engineer knows how TDD is used, and also understands that UnitTest has a good protection for the quality of the code

But another benefit that is less discussed should be "learning".

Although generally speaking, we write Testing to test and protect known things (Business logic)

It is relatively rare to do unknown exploratory tests, but in the case of writing Testing, there is still a chance to learn (so everyone is encouraged to write more tests Open-mouthed smile)

Below I share a case of testing and learning to your friends

This case is actually very simple, I wrote a UnitTest to test EPPlus after reading the Excel template I created

It can correctly judge whether a certain Cell has the correct Dropdownlist setting.

The Excel example looks roughly like this

image

Let's see how EPPlus adds Dropdownlist to Cell

image

Interested in the same shoes can refer to: https://github.com/JanKallman/EPPlus/wiki/Data-validation

The next step is to write down the "expected test"

From the official example, here I intuitively think that the formula set should be in the Cell, why?

The reason is that all I want to verify here is that the A2 Cell has the expected settings

image

It doesn't look as expected, and you can also see that the field's Formula is empty
image

Next, see if it is in the DataValidation of Cell

image

You can see that there are no related properties in DataValidation that can be used

Finally, you can see that the added DataValidation is actually placed in the DataValidations property of the sheet

image

image

It can be clearly seen that the formula we set earlier is here

From this step by step, I believe that you should have found that from the initial guess and trial and error, we found and learned that after EPPlus has set the DataValidation of the Cell, there is actually no information on the original Cell that can be verified. Whether we are successful or not, we finally learned that the relevant information is stored in the DataValidations of Sheet

The above is a simple test and learning case. I don't know if any of you have a similar experience?

Note: I found out later while writing this example that if I set up DataValidation manually on Excel rather than through the EPPlus suite, it is completely missing in the program. It will also report an error when getting DataValidations. It seems that I have learned a new knowledge.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325069316&siteId=291194637
one
ONE