background preloader

Testing

Facebook Twitter

Bdd

Introducing Sweet. In this post I introduce Sweet, the fully complete test framework (even with IDE support) in only 99 lines of code. Sweet is compiled against the new Scala-2.8.0.Beta1-RC1, and works great with simple build tool 0.6.3. Sweet lives at: Your First Sweet Sweets are just like ScalaTest's FunSuite, using the test("name"){ ... } style. The syntax is exactly the same: class HelloWorldSweet extends Sweet { test("hello, world! ") Just this (and one minor sbt configuration) will get you fully up and running with simple build tool. Assertions Sweet currently offers only two assertions, in matchers style: mustBe and mustNotBe. Class HelloWorldSweet2 extends Sweet { test("hello, world! And while were at it, let's how a quick boolean example: class BooleanAssertionExampleSweet extends Sweet { test("hello, world!

") I know it's not much, but it probably covers 90% of common assertions, which are normally of the form: assertEquals( 1, 1 )assertTrue( something ) Running in the IDE. JsMockito - Simple & Better Javascript Mocking. I recently put my developer hat back on and spent a few weeks doing some heavy Javascript development on a ThoughtWorks project in our Pune, India office. As well as writing code, I was also encouraging more and better unit testing of the Javascript codebase - but I was constantly frustrated by the lack of a good mocking library that let me do the sort of things I wanted to do (like mock callback functions). So in my spare time I put together JsMockito , a Javascript mocking library heavily inspired by the awesome Mockito mocking library for Java.

Give it a go and tell me what you think. Why drink it? JsMockito is a JavaScript stub/mock framework heavily inspired by Mockito . To quote the mockito website: JsMockito aims to try and reproduce the clean & simple API, with a JavaScript twist. What do you serve it with? JsMockito must be served with JsHamcrest . How to drink it? JsHamcrest.Integration.screwunit(); JsMockito.Integration.screwunit(); var mockedObject = mock(Array); Community Welcome Page. A Functional Test Harness. Using monads to thread state, we make a purely functional version of the test harness To paraphrase Crocodile Dundee, this isn't a monad tutorial this is a monad tutorial.

However, I decided to do something that would help me to understand monads, and that is to use them in a practical way. The object-oriented test framework we developed doesn't feel very idiomatic and as I learn more about FP, and it feels as if we could do something a lot nicer. So I set about thinking so how to make a purely functional test framework. The first thing that strikes you is how useful state is. In a purely functional framework we have to thread that state through our functions, and one elegant way to do that is through monads.

Now if you read the monad tutorial, you will realise that a monad is a magic box and all you can really do with a monad is put something in the box, or apply a function which will return another magic box. So without further ado, our monad: Nifty, no? Let ( >>= ) = State.bind. Scala and EasyMock. Testing With "The Force". Rich Hickey on Testing. It was an interesting week at JavaOne, with lots of talks and hallway discussions about new languages on the JVM . One of those languages is Clojure. Rich Hickey, the creator of Clojure, gave a talk at the Bay Area Clojure User Group Wednesday evening. During the Q&A part, he said that he’s not big on writing tests, although he always runs the tests that other people have written before he commits changes. Of course, there are many people, including us Object Mentors, who consider TDD to be an essential part of professional software development.

Obviously not everyone agrees. James Coplien has been another critic of this view. We should never accept any dogma. Driving the design. Building a suite of automated regression tests. So, if you can satisfy both requirements without TDD , then technically you don’t need it. Rich also made an off-hand comment that if he screws something up, he’s got thousands of users who will let him know! Yet Another JavaScript Testing Framework. By Miško Hevery & Jeremie Lenfant-engelmann Did you notice that there are a lot of JavaScript testing frameworks out there? Why has the JavaScript community not consolidated on a single JavaScript framework the way Java has on JUnit. My feeling is that all of these frameworks are good at something but none solve the complete package.

Here is what I want out of JavaScript unit-test framework: I want to edit my JavaScript code in my favorite IDE, and when I hit Ctrl-S, I want all of the tests to execute across all browsers and return the results immediately. I don’t know of any JavaScript framework out there which will let me do what I want. In order to achieve my goal I need a JavaScript framework with these three features: Command Line Control Most JavaScript test runners consist of JavaScript application which runs completely in the browser. On my continuous build machine I need to be able to run the same tests and somehow get the failures out of the browser and on to the status page.

Demo. Code Coverage of Clojure Code. Since pulling in Dmitry's test-compile mojo, and adding a test script runner mojo to the clojure-maven-plugin I thought I'd try something fun like running the maven emma plugin against a very simple test project. I was pleasantly surprised to see some fairly useful (ish) coverage data come back: You can easily see coverage information for your code, even if you end up trying to decipher clojures generated class names.

You even get fairly useful breakdown on the class detail, even if there's only the one method on each class: Once you've installed the clojure-maven-plugin, simply configure the plugin in your pom.xml: org.clojure clojure-maven-plugin clj-web-crawler smx-api src/test/java/test.clj compile test Adding these simple automated compile, test, and coverage processes to a clojure's impressive arsenal clojure already offers gives me a greater level of trust to experiment and use the young language in projects destined for a production environment. Comments (0) Add Comment. JavaScript Testing Does Not Scale. (This is a follow-up on my portion of the More Secrets of JavaScript Libraries panel at SXSW.) It’s become increasingly obvious to me that cross-browser JavaScript development and testing, as we know it, does not scale. jQuery’s Test Suites Take the case of the jQuery core testing environment. Our default test suite is an XHTML page (served with the HTML mimetype) with the correct doctype.

In includes a number of tests that cover all aspects of the library (core functionality, DOM traversal, selctors, Ajax, etc.). Next, we have a test suite that serves the regular XHTML test suite with the correct mimetype (application/xhtml+xml). Both of those tweaks (one with correct mimetype and one with no doctype) would also need to be done for the offset test suite. We have another version of the default jQuery test suite that runs with a copy of Prototype and Scriptaculous injected (to make sure that the external library doesn’t affect internal jQuery code).

In every browser that we support. Functional Programming Unit Testing - Part 4. In our previous installment, we talked about bringing together the traditional xUnit tests and QuickCheck property-based tests together in a single cohesive step. For this installment, let's talk about test coverage. But, before we continue, let's get caught up to where we are today: Code Coverage Code coverage is an important metric used as part of our design process to describe to what degree our source code has been tested.

The code coverage tools inspect the code directly as a form of white box testing of your code. I believe having a high code coverage percentage is important, although such hard-line stances of 100% path code coverage required is most often unnecessary and is evil. What do we consider as part of the criteria when we're calculating code coverage? Function coverage All functions in the program called? Of course some of these are connected in some way such as the following: Where should we focus?

Code Coverage with Haskell Program Coverage (HPC) --file Encryption.hs #light. Functional Programming Unit Testing - Part 2. In the previous post, we talked about some of the basics of functional programming unit testing. That post mostly focused around HUnit, which is a traditional xUnit testing framework. This time, let's focus on type-based property testing, which is to create specs which assert logical properties about a function, and then to generate data to test in an attempt to falsify these assertions, through the use of a tool called QuickCheck. Much like the traditional xUnit frameworks, this tool helps us flush out the specifications of our software through the use of tests.

Unlike the xUnit frameworks, however, this framework allows us to create generators to help flush out our behaviors and capture our edge cases as we look for ways to falsify our tests. These generators could use either random data or well structured data that you can craft. Let's dive a little deeper into what that means. But, before we continue, let's get caught up to where we are today: Part 1 - xUnit Frameworks - HUnit #light. Genetic A/B Testing with JavaScript. I’ve long been interested in the concept of A/B testing (Also called split testing). It’s a simple concept that should sit will with most mathematically-inclined types: You have a baseline interface in which you adjust a single variable, at random, for each user that visits your application.

After a given amount of time you should be able to see if certain variables affect how your users behave (either negatively or positively). A product was recently released called SnapAds which allows its users (advertisers) to permute different variations of an ad and display different versions to users, based upon how well they perform over time. But that’s not what I was interested in, specifically (even though it is a cool idea). This means that no matter how many different A/B tests you have on a page the genetic algorithm will adapt to the input (users visiting the page and hopefully achieving some pre-defined goal) and slowly show a more-optimal page layout to the user.

Comments are closed. ScalaCheck 1.5. Version 1.5 of ScalaCheck is now available. ScalaCheck is a tool for automatic unit testing of your Scala and Java programs, developed by Rickard Nilsson. ScalaCheck allows you to define general properties about your code units, while the tool handles all test data generation for you: you can run thousands of unit tests automatically without writing and maintaining an endless number of test cases. ScalaCheck started out as a Scala port of the Haskell library QuickCheck, and has since evolved and been extended with features not found in Haskell QuickCheck.

Version 1.5 of ScalaCheck introduces support for Scala 2.7.2 and various minor feature additions. Please visit for change history, user guide, API reference and more. ScalaCheck's highlights Properties are tested automatically, with test data generated by ScalaCheck. A small example, using the Scala interpreter with ScalaCheck on the path: sbaz update sbaz install scalacheck sbaz upgrade. Tsung. Test. Google's framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian).

Based on the xUnit architecture. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, value- and type-parameterized tests, various options for running the tests, and XML test report generation. Getting Started After downloading Google Test, unpack it, read the README file and the documentation wiki pages (listed on the right side of this front page). Who Is Using Google Test? In addition to many internal projects at Google, Google Test is also used by the following notable projects: The Chromium projects (behind the Chrome browser and Chrome OS) The LLVM compiler Protocol Buffers (Google's data interchange format) If you know of a project that's using Google Test and want it to be listed here, please let googletestframework@googlegroups.com know. Google Test-related open source projects.

Mock Roles... not Objects. The Invisible Branch. Full statement coverage may be necessary for good testing coverage, but it isn't sufficient. Two places where statement coverage will be inadequate are branches and loops. In this episode, we'll look at branches, and specifically the differences between statement coverage and branch coverage. Let's consider a case where branch coverage and statement coverage aren't the same. Suppose we test the following snippet. We can get complete statement coverage with a single test by using a berserk EvilOverLord: bool DeathRay::ShouldFire(EvilOverLord& o, Target& t) { double accumulated_rage = 0.0; if (o.IsBerserk()) accumulated_rage += kEvilOverlordBerserkRage; accumulated_rage += o.RageFeltTowards(t); return (accumulated_rage > kDeathRayRageThreshold);} But what if DeathRay should fire at this Target even with a non-berserk Overlord?

If (o.IsBerserk()) { accumulated_rage += kEvilOverlordBerserkRage; } else { } Why do we add an else clause if it doesn't actually do anything? Riffing on Romance, was Re: My Modernism Hurts. --- In postmodernprogramming@yahoogroups.com, "mfeathers256" >I remember once [...] Kent > was talking about the Money example he used in the TDD book. I forget > what he said I remember it was something along the lines that he found > it a different way of doing Money and it was just the right way.. the > way that it is supposed to be. When he said that I said to myself > "whoa.. I feel that way about great design too.. that when we find it > we are discovering something about the universe, something that is > there and singular, but I'm suspicious of that belief. " > > Enter postmodernism. I'm reminded of one of Heinlein's juveniles ("Tunnel in the Sky"). (When you get bored, search ahead to [*] to reach the punchline.)

So, what can we do with this as regards software? I now understand that mainly this was all about Us (the UK developers) and Them (me an my pal in SG), and some surprising results about just whom had what ego invested in the code, and so on. Back to Dijkstra. Keith. Watir. Web app testing with Python part 3: twill. In a recent thread on comp.lang.python, somebody was inquiring about ways to test whether a Web site is up or not from within Python code.

Some options were proposed, among which I referred the OP to twill, a Web application testing package written in pure Python by Titus Brown (who, I can proudly say, is a fellow SoCal Piggie). I recently took the latest version of twill for a ride and I'll report here some of my experiences. My application testing scenario was to test a freshly installed instance of Bugzilla. I wanted to see that I can correctly post bugs and retrieve bugs by bug number. Using twill, all this proved to be a snap. First, a few words about twill: it's a re-implementation of Cory Dodt's PBP package based on the mechanize module written by John J. Lee. Twill can be used as a domain specific language via a command shell (twill-sh), or it can be used as a normal Python module, from within your Python code.

[ggheo@concord twill-latest]$ twill-sh -= Welcome to twill! #! EclEmma - Java Code Coverage for Eclipse. Software testing death spiral. Testing Websites with Twill. Pylot.