Skip to content

mhshams/spek

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spek

A Specification framework for Kotlin

License

Licensed under Modified BSD (See LICENSE.TXT) for full license

Usage

Spek is a specification framework for Kotlin, allowing you to define your specifications in a fluent and easy to read way.

Writing specifications

A specification is a class that is inherited either from JUnitSpec or from ConsoleSpec:

public class calculatorSpecs : JUnitSpec() {{
    given("a calculator")
    {
        val calculator = Calculator()

        on("calling sum with two numbers")
        {
            val sum = calculator.sum(2, 4)

            it("should return the result of adding the first number to the second number")
            {
                shouldEqual(6, sum)
            }
        }
    }
}}

Since they are merely functions, specifications do not need to belong to a class and can be declared as top-level functions in Kotlin. This gives you complete liberty to organize your specifications as you wish.

Runners

You may write tests with Spek either for provided standalone console runner, or as JUnit tests. JUnit tests are run under standard JUnit 4.x tests runner.

FAQ

Q: What is Kotlin?
Kotlin is an Apache 2 OSS Language targetted at the JVM and JavaScript and is developed by JetBrains It is aimed at being a concise modern language for general use. It also rocks!

Q: Is Kotlin free to use?
While this is not a Kotlin FAQ, it is important to note that Kotlin is free to use and you can use the command line or the Community Edition of IntelliJ to develop with it (which is free and OSS). Obviously IntelliJ Ultimate also works! There's also an Eclipse plugin in the works. Check the project site for updates.

Q: Is Spek a BDD or a TDD framework?
Spek in Dutch means Bacon, so you could think of it as a Bacon Driven Development framework. Being serious for a moment though, we (at least the original author) believe that there is a false distinction in frameworks around what TDD or BDD is. Unit tests are ultimately about defining the specifications of your system. As such, Spek is merely a specification framework if it can be called anything. For more information read What BDD has taught me

Q: Can I have more than one on per given?
Yes you can. How you group your specifications is up to you

Q: Can I have more than one it per on?
Yes you can. In real world applications, an action can lead to several reactions.

Q: Isn't it bad to have more than one assertion per test?
Traditionally, in unit testing it's been recommended that you should limit each test to one assertion with the idea that you test a single unit, and at the same time, find it easy to see where a test has failed. In Spek you can still comply with this guidance. You can have multiple it but you limit each to one assertion.

Q: Why is the logo a piece of bacon?
We don't have a logo, but if you want to make one, let it be Bacon. English bacon that is. Spek was originally codenamed kspec. Someone suggested to rename it to Spek which kind of fits. Turns out, Spek is Bacon in Dutch. So why not have bacon as a logo? After all, we love bacon!

Q: Can I contribute?
Please do!

About

A specification framework for Kotlin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 99.2%
  • Shell 0.8%