Stubbing authentication in request spec

A request spec is a thin wrapper around ActionDispatch::IntegrationTest, which doesn’t work like controller specs (which wrap ActionController::TestCase). Even though there is a session method available, I don’t think it is supported (i.e. it’s probably there because a module that gets included for other utilities also includes that method). I’d recommend logging in by posting … Read more

What Makes a Good Unit Test? [closed]

Let me begin by plugging sources – Pragmatic Unit Testing in Java with JUnit (There’s a version with C#-Nunit too.. but I have this one.. its agnostic for the most part. Recommended.) Good Tests should be A TRIP (The acronymn isn’t sticky enough – I have a printout of the cheatsheet in the book that … Read more

Testing Spring’s @RequestBody using Spring MockMVC

Use this one public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName(“utf8”)); @Test public void testInsertObject() throws Exception { String url = BASE_URL + “/object”; ObjectBean anObject = new ObjectBean(); anObject.setObjectId(“33”); anObject.setUserId(“4268321”); //… more ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter(); String requestJson=ow.writeValueAsString(anObject ); mockMvc.perform(post(url).contentType(APPLICATION_JSON_UTF8) .content(requestJson)) .andExpect(status().isOk()); } As described … Read more

Unit Test? Integration Test? Regression Test? Acceptance Test?

Briefly: Unit testing – You unit test each individual piece of code. Think each file or class. Integration testing – When putting several units together that interact you need to conduct Integration testing to make sure that integrating these units together has not introduced any errors. Regression testing – after integrating (and maybe fixing) you … Read more

Embedded MongoDB when running integration tests

I have found Embedded MongoDB library which looks quite promising and does what you have asked for. Currently supports MongoDB versions: 1.6.5 to 3.1.6, provided the binaries are still available from the configured mirror. Here is short example of use, which I have just tried and it works perfectly: public class EmbeddedMongoTest { private static … Read more

RSpec vs Cucumber (RSpec stories) [closed]

If you haven’t already, you might want to check out Dan North’s excellent article, What’s in a Story? as a starting point. We have two main uses for Cucumber stories. First, because the story form is very specific it helps focus the product owner’s articulation of the features he wants built. This is the “token … Read more

Junit: splitting integration test and Unit tests

You can split them very easily using JUnit categories and Maven. This is shown very, very briefly below by splitting unit and integration tests. Define A Marker Interface The first step in grouping a test using categories is to create a marker interface. This interface will be used to mark all of the tests that … Read more

Separating unit tests and integration tests in Go

@Ainar-G suggests several great patterns to separate tests. This set of Go practices from SoundCloud recommends using build tags (described in the “Build Constraints” section of the build package) to select which tests to run: Write an integration_test.go, and give it a build tag of integration. Define (global) flags for things like service addresses and … Read more

Prevent unit tests but allow integration tests in Maven

I found the simplest way to skip only surefire tests is to configure surefire (but not failsafe) as follows: <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration> <!– skips surefire tests without skipping failsafe tests. Property value seems to magically default to false –> <skipTests>${skip.surefire.tests}</skipTests> </configuration> </plugin> This allows you to run mvn verify -Dskip.surefire.tests and only surefire, not … Read more