Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine for C# and/or Java

Tags:

java

c#

jasmine

Jasmine is a nice unit testing framework for JavaScript. It not only tests your code, it provides a nice way to document it by:

  • Using a fluent BDD-ish way to define tests that in itself almost reads like a documentation
  • The test report reads like a documentation too

I'm wondering if anything comparable exists for C# and/or Java.

like image 374
chiccodoro Avatar asked Oct 16 '12 16:10

chiccodoro


People also ask

What is Jasmine code?

Sample Code. Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

What is Jasmine framework used for?

Jasmine is an open-source testing framework for JavaScript. It aims to run on any JavaScript-enabled platform, to not intrude on the application nor the IDE, and to have easy-to-read syntax. It is heavily influenced by other unit testing frameworks, such as ScrewUnit, JSSpec, JSpec, and RSpec.

Is Jasmine BDD or TDD?

The current home page of Jasmine says that it's “a behavior-driven development framework for testing JavaScript code.” So the intent of Jasmine is to be a BDD testing framework, per its authors. So, while the authors of Jasmine have intended it as a BDD testing framework, it can also be used with TDD and unit testing.


2 Answers

I just came across NJasmine on GitHub. I've never used it but thought this might help others like myself that want the awesome of Jasamine in C# unit tests.

From the GitHub:

NJasmine is a RSpec-ish test language inspired by the javascript test library Jasmine (https://github.com/fschwiet/DreamNJasmine) for C# / .Net programming.

given("some preconditions", () => {

    var range = 10;

    when("the system under test is ran", () => {

        var sut = new SystemUnderTest();

        bool score = arrange(() => sut.Fire(range));

        then("win!", () => {

            expect(() => score);
        });
    });
});

Available on Nuget: http://nuget.org/List/Packages/NJasmine

Again, I can't vouch for this as I haven't used it, but I hope this will help others make informed decisions.

HTH

like image 96
GraehamF Avatar answered Oct 06 '22 06:10

GraehamF


Oleaster is a Java testing framework with clean simple syntax, extensively using Java 8 arrow functions. It is executed using JUnit runner.

Code sample from hompage:

@RunWith(OleasterRunner.class)
public class OleasterIntroductionTest {{
    describe("A suite", () -> {
        it("contains a spec with an expectation", () -> {
            expect(40 + 2).toEqual(42);
        });
    });
}}
like image 33
czerny Avatar answered Oct 06 '22 06:10

czerny