unit testing in clojure - clojure

I am new to Clojure and I'm trying to write my unit tests. What is the best way to write unit tests in Clojure and how do I import the file where my functions are defined to my unit test.
Thanks for the help.

To start with, there's clojure.test. Using Leiningen, you can call lein test to run the tests.
See also Speclj which is useful for BDD.

Another accepted way to do unittest in clojure is using Midje.
I have read good comments about it.

Speclj is also a testing framework for the clojure language widely accepted that you may consider as well. Here you can find a longer discussion about it's strong-weak points

Related

Common questions TDD with Mock

I don't know how use TDD in C++ projects, but I decided use "Google Mock Framework" for a start.
But I have one question:
When I finish testing, do I have to clean up my code from TDD's macros, class and etc?
In other words, should the release version of my project include Google Mock?
P.S.
What do you advise for learning TDD on practice? (Articles, Books and etc.)
You can try this book: TDD By Example. It uses java, but I think it will help :)
In my opinion, there's no need to remove the testing code from the release version of the project. Test code should be developed in such a way that it is part of the final product i.e. it follows the same standards, is maintainable and follows good unit testing practises (see The Art of Unit Testing).
As part of TDD you should also be performing continuous integration builds that run after code is delivered. This build process should run through all (active) unit tests to make sure that nothing has been inadvertently broken (We use Anthill Pro). If you remove your test code prior to building, this process won't be possible.
There's a good article here by James Shore that might be worth read.

EasyMock gentle introduction?

I am completely baffled while trying to use EasyMock. Does anybody know of a (very) gentle introduction to EasyMock?
I already heavily use TDD, and I use mocking (which I guess is almost a prerequisite for doing TDD). I have just never used a framework for mocking before.
Here are some articles you might like:
Easier testing with EasyMock
Unit testing with JUnit and EasyMock
Mock Object Testing With EasyMock 2
Getting Started with EasyMock2
You could also check out other mocking frameworks such as Mockito, PowerMock and JMockit.
How about their own Documentation? http://easymock.org/EasyMock3_0_Documentation.html
Have you tried this tutorial? http://www.vogella.de/articles/EasyMock/article.html
Do you already have a background in Test Driven Development? If not, I'd get my hands on a copy of Roy Osherove's book The Art of Unit Testing. http://artofunittesting.com/

Is It Possible to do Context/Specification Testing With MSTest?

I'm moderately new to test frameworks and I have been reading up on Moq and this introductory post used a way of organising tests that I had not seen before. Further research shows that we in the .Net world tend to meld the terms BDD and Context/Specification (CS) Testing. I don't want to get into that argument - I am primarily interested in achieving this style of writing test classes.
This article shows the approach again and makes explicit the use of a base class that allows us to construct our specification through the test framework.
This issue I have is that I cannot see an instance method under MSTest that would allow a test fixture to be initialised just once for each test. The best I can see is the constructor of the test class but that feels a bit wrong. In NUnit one could use [TestFixtureSetup]. Is there an equivalent using Visual Studio's built in test framework?
Edit
I've subsequently moved to NUnit which provides the flexibility I require.
After some investigation I have moved to using NUnit. There are several reasons for preferring NUnit over MSTest but, with regards to this particular issue, the compelling reason is that the only class-wide initialisation method supported by MSTest (that doesn't run for every test) is for static methods which is not what I'm looking for.
As Jason points out [ClassInitialise] will provide this static, class wide initialisation in MSTest. There isn't really a way of mimicking the behavior of [TextFixtureSetup] found in NUnit such that an instance method is run once before any test in the fixture is run.
To replicate NUnit's [TestFixtureSetUp] for MSTest, try [ClassInitialize]. Here's the link where I found that information. This is another useful blog article that might help you.

Good examples of unit test suites

For those of us who like to learn by reading good code, what are some of the projects you've seen which provide a great example of a medium to large suite of unit tests in action?
This isn't a question about what your favourite unit testing framework is, but it could be helpful to add which unit testing and/or mocking frameworks are used by the projects you mention.
Any platform will do, but I'm mainly interested in projects which use an xUnit-style unit testing framework in .NET.
Apache CXF has a mind-numbingly large array of unit tests. They are written to Junit, and include the JUnit-Spring mechanisms as well as one of the mock libraries. They include launching processes and many other mechanisms you might need some day.
For example, ReportLab uses Python's unittest module (also known as PyUnit) and has lots unit test that you might want to take a look at.
I'm also using unittest myself. It is very similar to Java's jUnit framework and thus very handy for writing tests in no time.
The Service Factory has about 780 unit tests, including some that test code meant to run inside of Visual Studio. It has some very good examples of mocking such code.
The Enterprise Library has even more.
NunitLite has a unit tests suite but I'm not sure it qualifies as a medium-sized project. I seem to remember NUnit also has unit tests, but its site currently is unavailable.

Unit testing in C++

I've been reading a lot about Unit tests and Test Driven developemnt.
Recently, I also read java unit test code.
I however, prefer to develop in Qt. So I googled up "unit testing in c++" and found a host of information about various unit testing frameworks available for C++.
However, I could not find a reliable comparison of the the various frameworks.
So I look to the SO community to guide me through the selection of what may the "best" unit testing framework for c++.
Also, if anybody had specific comments regarding TDD in Qt (especially using Qt-Creator), then they are more than welcome.
Usually use Boost, but if you are using Qt, their QtTestLib might be the better choice.
I would recommend doctest (created by me) - it's the lightest on compile times from all the popular testing frameworks. It is also a direct competitor to Catch which is currently the most used framework - checkout the differences in the FAQ
This seems too be the same question as:
Unit testing in C++ which is actually c++ despite the URL title.
From there, they link to two more SO questions which should help:
Unit testing for C++ code - Tools and methodology
C++ unit testing framework
There is a table comparing all (?) the C++ unit test frameworks available from wikipedia.
There also is an old comparison of C++ unit test frameworks available. I do not think it has not been updated so I mention it as a complement as it's more argumented than the table. It covers, CppUnit, CppUnitLite, Boost.Test, NanoCppUnit, Unit++, CxxTest, especially it does not cover Google C++ framework.
The "xUnit" family of testing frameworks is usually pretty solid (jUnit, NUnit, etc.). I haven't used it myself, but there is a port of jUnit for C++:
http://sourceforge.net/projects/cppunit
Boost is usually a good choice, and it contains a testing framework, the Boost Test Library. I have used it for small test cases and it did what I expected, but I haven't used it extensively like in TTD.
If you want to get off the ground quickly without figuring out how to build a library, there is a single header file include solution, which supports fixtures (setup and teardown), the usual TEST() {} with CHECK_TRUE, etc.
It also has memory leak detection and performance testing capabilities.
https://gitlab.com/cppocl/unit_test_framework