Transforming a List

Lambda expressions are lightweight, highly concise anonymous methods backed by functional interfaces in Java 8. You can use them to leap forward into a whole new world of programming in Java. With functional programming capabilities, which have been around for decades in other languages, you can now write elegant, concise, less

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Employ Test Doubles

Test-Driving JavaScript Applications — by Venkat Subramaniam (34 / 108)

👈 Separate Dependencies Where Possible | TOC | Inject the Dependencies 👉

Test doubles are objects that replace real dependencies to enable automated testing. Test doubles are the automated testing equivalent of movie stunt people — they take the place of the original since having the real one is expensive or impractical. You will learn the role of test doubles using the setLocation function as an example.

The setLocation function is a simple one. It takes a URL for Google Maps and sets that into the location property of the window object, thus instructing the browser to display the map with the user’s current location. It’s easy to write but may appear hard to test.

We don’t want to load an HTML page in a browser, then call the setLocation function to see if the browser navigates to the page at the given URL — that would be manual, not automated. We could write a UI-level test, way up at the top of the test pyramid. But we discussed that if a test can be written at a lower level then we should.

The issue here is that we’re setting the location property of the window object that’s provided by the browser, and when set, it will respond by making a request to that page. How we test for that, automated and at a lower level, is the real concern.

It turns out we don’t have to really test for that. Our goal is not to test if the browser responds to a set of the location. We need to verify that the setLocation function properly sets the location property of a window object — that’s right, “a” window and not “the” window. Let’s discuss further what that means. We can break the testing for the overall behavior of page navigation into three parts:

Add a comment

Related posts:

The Surprising Result of Confronting the Racist Uncle

I am not a confrontational person. Put me in a group of people and I will automatically measure and consider how every word out of my mouth is likely to land. I have very strong opinions but I am…

Venture Capital Cool Math

How well do you know the US state capitals? There are three ways to play this game: Select: multiple choiceSpeed: Write your answer … and don’t forget to take advantage! Locate: Place the star where…

Luna Nodes Shifting Signs July 17th 2023

The Nodes take an 18 month period to travel within a sign. The Lunar Nodes of fate will leave the Signs of Taurus and Scorpio and move into the signs of Aries and Libra on Monday July 17 2023…