YipWWong / hello-world

1 stars 0 forks source link

Addition function using JS + Unit Testing #6

Open winstoncwang opened 4 years ago

winstoncwang commented 4 years ago

DESCRIPTION The function takes in two numbers as arguments and returns the sum of the two number.

Example: Input:2,3 Output:5

Unit test the function before actually writing the programming code. (TDD)

winstoncwang commented 4 years ago

Github repo link for the function used to return the sum of two numbers. https://github.com/winstoncwang/Sandbox/tree/master/Sum_of_two_numbers

YipWWong commented 4 years ago

This is good. can you also add as a test, not a number? (error handling) what about other edge cases like large numbers, decimals (are there floating point exceptions)?

also why are you using before when loading the fn? does it load it before running each individual test? why would you need that? are there instantiation issues? what about multi threading? this is difficult to write a multi threading test. so ignore unless you have nothing else to do. what I am trying to get at is: do you understand why you are using before? what other things can you use? Or another way to instantiate the function?

read up on test setup and teardown.

good work.

kind regards,

Yip

On Mon, 14 Sep 2020 at 22:50, Winston Wang notifications@github.com wrote:

Github repo link for the function used to return the sum of two numbers. https://github.com/winstoncwang/Sandbox/tree/master/Sum_of_two_numbers http://url

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/YipWWong/hello-world/issues/6#issuecomment-692332872, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ54AJQQW6MUNAKDBTHHSUDSF2FZXANCNFSM4RK4FITA .

winstoncwang commented 4 years ago

Hi @YipWWong ,

I will be making an update to the previous test and fn file. At that point, I don't think it is necessary for any before/beforeEach hook to be used. Since the fn is a functional method which doesn't store any data to affect tests after use. Please correct me if I'm wrong.

I am currently working on Mongoose, so it would be necessary to instantiate and remove the mocked object after every test run( hence the setup and teardown of testing).

I thought JS is single-threaded, correct me if I am wrong. But I would love to learn about writing multi-threading tests. What I am finding hard to do at the moment is to define exactly what I am testing. Does that come with experience? For example, testing endpoint using mock testing. Unless I know the JSON structure of the query result returned, I will not be able to write an accurate test to provide sufficient confidence.

YipWWong commented 4 years ago

Agreed about not needing a setup/teardown in this case. for anything where you are mocking you will need some sort of setup/teardown.

for multi threading you can read but not essential just yet: https://blog.logrocket.com/node-js-multithreading-what-are-worker-threads-and-why-do-they-matter-48ab102f8b10/ this will only be a problem if we have a lot of users.

defining what needs testing is an art, and will come with experience or you can just ask. there are books about this.

we can discuss later on today if you want.

On Wed, 16 Sep 2020 at 21:30, Winston Wang notifications@github.com wrote:

Hi @YipWWong https://github.com/YipWWong ,

I will be making an update to the previous test and fn file. At that point, I don't think it is necessary for any before/beforeEach hook to be used. Since the fn is a functional method which doesn't store any data to affect tests after use. Please correct me if I'm wrong.

I am currently working on Mongoose, so it would be necessary to instantiate and remove the mocked object after every test run( hence the setup and teardown of testing).

I thought JS is single-threaded, correct me if I am wrong. But I would love to learn about writing multi-threading tests. What I am finding hard to do at the moment is to define exactly what I am testing. Does that come with experience? For example, testing endpoint using mock testing. Unless I know the JSON structure of the query result returned, I will not be able to write an accurate test to provide sufficient confidence.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YipWWong/hello-world/issues/6#issuecomment-693648229, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ54AJQYT26YU4G4K6AEQILSGEN5FANCNFSM4RK4FITA .