DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Testing, Deployment, and Maintenance Topics

article thumbnail
CoffeeScript: a TDD example
CoffeeScript is a language building an abstraction over JavaScript (as the similar name suggests.) It is an abstraction over the syntax of JavaScript, not over its concepts: the language is still based on functions as objects which may bind to other objects, and prototypical inheritance. CoffeeScript favors the best practices of JavaScript by transforming abstractions you would have written anyway, or borrowed from a framework, into language concepts for maximum conciseness. It has a compilation step - as every language must compile to a lower-level one, like C or Java. Since cowboy coding is not my preferred way to work, I prepared a Test-Driven Development example by using jsTestDriver. In this article, you get two things: a CoffeeScript introduction, and the tools for unit testing it (and consequently, how to TDD with CoffeeScript). Building on Top of JavaScript There is something to be said for those who go out of their way to try to improve the infrastructure of existing programs. Many have taken a stab at it by creating tools that are a compliment to JavaScript, and it appears to have worked quite well in this case. The reason? Because JavaScript is in need of some improvements. One of the programs that people have come up with is CoffeeScript. It is literally a bit of computer code that overlays the existing JavaScript codes to make it read even more fluidly. The benefit that one gets from this is that they can start to use JavaScript in a more efficient way with fewer bumps in the road. As it stands right now, JavaScript has numerous challenging issues that we must recognize. However, that can all be amended by using JavaScript as it was intended and just working towards perfecting it. CoffeeScript is certainly not the end all be all of the programs for improving JavaScript, but it is a great step in the right direction. People should at least try out the CoffeeScript code to see if it may be useful to them in terms of improving the quality of codes that they receive from JavaScript. If so, then it will have been worth the trouble. The infrastructure The basic structure consists of two folders: src/ and lib/; remember the compilation step. We'll put .coffee files into src/ and compile them to .js equivalents in a symmetrical tree in lib/. We add also a jsTestDriver.conf file to tell the unit testing framework all the files to load, which are only the "binary" .js scripts: server: http://localhost:4224 load: - lib/*.js Compiling This is the first version of the test I've managed to write, fizzbuzztest.coffee. It is a tautology that should always pass: mytest = () -> assertEquals(1, 1) tests = { "test1is1": mytest } TestCase("tests for fizzbuzz kata", tests) You see here that functions are still first-class objects, but only anonymous functions are supported. CoffeeScript is a Python/Ruby-like language without semicolons, and there are some affinities and common backgrounds with the latter language. I still use the old syntax for calling functions for now, although parentheses can be omitted in many cases. CoffeeScript is conservative, and even accepts semicolons if you want to write them. I compiled this script with coffee -o lib/ -c src/. fizzbuzztest.js is the result: (function(){ var mytest, tests; mytest = function() { return assertEquals(1, 1); }; tests = { "test1is1": mytest }; TestCase("tests for fizzbuzz kata", tests); })(); The global namespace is not touched by default, and var keywords are automatically introduced to preserve it. When I later needed the global namespace, I wrote: this.fizzbuzz = /* ... function definition ... */ This in this case is the window object or the other global object where you execute the code. Running To run the test, we must initialize the test driver (only once): jsTestDriver java -jar JsTestDriver-1.3.2.jar --port 4224 jsTestDriver will now listen at localhost:4224. Load this URL in your browser and capture it by clicking on the link. Tests will be executed inside the browser when requested: for more details see the related article. Every time you want to run the tests, execute them from the command line: java -jar JsTestDriver-1.3.2.jar --tests all This is the complete history of my kata. Here is the final version of the code (spoiler alert!), with support for addition of other factors than 3 or 5. The code is probably uglier than average, but it compiles: tests = { "test ordinary numbers are unchanged": -> assertEquals(1, fizzbuzz(1)) assertEquals(2, fizzbuzz(2)) assertEquals(4, fizzbuzz(4)) assertEquals(142, fizzbuzz(142)) "test multiples of 3 become fizz": -> assertEquals("Fizz", fizzbuzz(3)) assertEquals("Fizz", fizzbuzz(6)) assertEquals("Fizz", fizzbuzz(9)) "test multiples of 5 become buzz": -> assertEquals("Buzz", fizzbuzz(5)) assertEquals("Buzz", fizzbuzz(10)) "test multiples of 3 and 5 become fizzbuzz": -> assertEquals("FizzBuzz", fizzbuzz(15)) assertEquals("FizzBuzz", fizzbuzz(45)) } TestCase("tests for fizzbuzz kata", tests) newRule = (word, divisor) -> (number) -> return word if number % divisor == 0 "" newFizzBuzz = (rules) -> (number) -> result = "" concatenation = (rule) -> result = result + rule(number) concatenation rule for rule in rules return result if result number fizzRule = newRule("Fizz", 3) buzzRule = newRule("Buzz", 5) this.fizzbuzz = newFizzBuzz([fizzRule, buzzRule]) Comments On The Experience CoffeeScript offers a shorter syntax, which presents a bit of a learning curve but not a steep one. I went through the whole example in 1 hour (I already knew how to use jsTestDriver, however.) Syntax shapes how you write code by making some things easier: I found myself using higher-order functions which create other ones more often, since creating a function now is just a matter of putting -> before some lines of code. Variable naming is also simpler as you just have to think of the name, not about var or polluting the scope. More time to dedicate to design, and less to language issues. Some one-liners like the instruction if the expression is handy but not essential, and are there due to Ruby's inspiration. There's, even more, to discover in CoffeeScript, such as the options for the binding of functions which helps not to lose the reference to this. However, the question is if all this convenience has more value than the time spent to learn a new language and add infrastructure to make it work - the compiler, the build hooks, and the parallel tree to ignore in your version control system.
August 12, 2022
by Giorgio Sironi
· 15,689 Views · 1 Like
article thumbnail
How to Govern Terraform States Using GitLab Enterprise
Most companies relying on Terraform for infrastructure management choose to do so with an orchestration tool. How can you govern Terraform states using GitLab Enterprise?
August 12, 2022
by Sefi Genis
· 5,012 Views · 1 Like
article thumbnail
4 Reasons MSPs Should Monitor Their GitHub Footprint
In this article, we will see why monitoring in real-time code-sharing platforms such as GitHub should be a top priority for any MSP.
August 11, 2022
by Thomas Segura
· 4,004 Views · 3 Likes
article thumbnail
How to Choose the Right Digital Experience Monitoring Solution
It would be best if you had digital experience monitoring for a transparent view of your IT infrastructure and how well it supports the needs of your customers.
August 11, 2022
by Mehdi Daoudi
· 3,582 Views · 1 Like
article thumbnail
Five Steps To Building a Tier 1 Service That Is Resilient to Outages
If Tier 1 services fail, it can mean disaster for a business. To ensure resiliency from outages, follow a proven five-step process.
August 11, 2022
by Pradeep Chinnam
· 6,820 Views · 4 Likes
article thumbnail
GitHub Events Are Booming! Are Bots the Reason?
This article dives deeply into GitHub event trending, why GitHub events are surging, and whether GitHub's architecture can handle the increasing load.
August 11, 2022
by Mia Zhou
· 4,783 Views · 3 Likes
article thumbnail
Azure Databricks Automated Testing Using Great Expectations and C#
This article will show you how to use the Great Expectations library to test data migration and how to automate your tests in Azure Databricks using C# and NUnit.
August 11, 2022
by Mohammed Basil
· 11,414 Views · 3 Likes
article thumbnail
SRE: From Theory to Practice: What’s Difficult About Tech Debt?
How do you get ahead of tech debt before it piles up? And how do you deal with tech debt you already have, without sacrificing velocity on new projects?
August 11, 2022
by Emily Arnott
· 6,040 Views · 1 Like
article thumbnail
Pull Request vs. Merge Request
Pull request vs. merge request, what is the difference?
August 10, 2022
by Yana Zinkevich
· 7,105 Views · 5 Likes
article thumbnail
10 Best Infrastructure-as-Code Tools for Automating Deployments in 2022
With the rapidly changing technology landscape, the traditional approaches to infrastructure are hampering businesses to adapt, innovate, and thrive optimally. Now, Infrastructure as Code (IaC) tools have emerged as the key to navigating this challenge.
August 10, 2022
by Vishnu Vasudevan
· 7,488 Views · 2 Likes
article thumbnail
Back to Basics: Accessing Kubernetes Pods
Kubernetes is a colossal beast. You need to understand many concepts before it starts being useful. Here, learn several ways to access pods outside the cluster.
August 10, 2022
by Nicolas Fränkel
· 4,782 Views · 4 Likes
article thumbnail
Decorator Pattern to Solve Integration Scenarios in Existing Systems
This article provides an example of how the Java Decorator Pattern helps create designs from scratch and fix integration problems in existing systems.
August 10, 2022
by Mario Casari
· 7,679 Views · 6 Likes
article thumbnail
The 2-Minute Test for Kubernetes Pod Security
Learn how to audit your clusters for compliance with the latest Kubernetes Pod Security Standards without installing anything in the cluster.
August 9, 2022
by Jim Bugwadia
· 6,928 Views · 2 Likes
article thumbnail
Sprint Goals: How to Write, Manage, and Achieve
This blog is an extended insight on the real purpose of Sprint Goals and how clearly defining and utilizing them can stack a business with benefits.
August 9, 2022
by Harshita Agnihotri
· 6,723 Views · 4 Likes
article thumbnail
Eclipse's RAP Push Session Revisited
If you're writing code for a web application using Java, read this post to learn about how to work with the newest updates to Eclipse.
Updated August 9, 2022
by Kees Pieters
· 6,342 Views · 2 Likes
article thumbnail
How To Migrate From ECS to EKS and the #1 Trick To Make EKS Easier
Looking to migrate from ECS to EKS, but you're not sure where to start? Explore this guide and learn how to make your EKS journey easier.
August 9, 2022
by Zilvinas Urbonas
· 3,817 Views · 1 Like
article thumbnail
Building a Slack Integration for Your SaaS Notification System
In this post, we offer details for developers who are planning to build a Slack integration for their notification system.
August 9, 2022
by Suhas Deshpande
· 4,837 Views · 2 Likes
article thumbnail
Auth0 (Okta) vs. Cognito
This article compares two authentication service providers: Auth0 and Amazon Cognito. Both of them are cloud-based identity management services.
August 8, 2022
by Anastasiia Komendantova
· 4,441 Views · 3 Likes
article thumbnail
Build a Java Microservice With AuraDB Free
For today’s adventure, we want to build a Java microservice that connects to, and interacts with, graph data in a Neo4j AuraDB Free database.
Updated August 8, 2022
by Jennifer Reif DZone Core CORE
· 9,891 Views · 5 Likes
article thumbnail
Externalize Microservice Configuration With Spring Cloud Config
How to set up a service that hosts the Spring Cloud Config server and to wire an existing microservice as the config client service.
Updated August 8, 2022
by Jennifer Reif DZone Core CORE
· 14,449 Views · 5 Likes
  • Previous
  • ...
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×