How to prepare a nested data structure for a data-driven test in Karate?

I don’t recommend nesting unless absolutely necessary. You may be able to “flatten” your permutations into a single table, something like this: https://github.com/intuit/karate/issues/661#issue-402624580 That said, look out for the alternate option to Examples: which just might work for your case: https://github.com/intuit/karate#data-driven-features EDIT: In version 1.3.0, a new @setup life cycle was introduced that changes the … Read more

Integration tests for AspectJ

Let us use the same sample code as in my answer to the related AspectJ unit testing question: Java class to be targeted by aspect: package de.scrum_master.app; public class Application { public void doSomething(int number) { System.out.println(“Doing something with number ” + number); } } Aspect under test: package de.scrum_master.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import … Read more

How can I skip tests in maven install goal, while running them in maven test goal?

It sounds like you didn’t understand the concept of the build life-cycle in Maven. If you run mvn install all life-cycle phases (including the install phase itself) run before the install phase. This means running the following phases: validate initialize generate-sources process-sources generate-resources process-resources compile process-classes generate-test-sources process-test-sources generate-test-resources process-test-resources test-compile process-test-classes test prepare-package package … 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

How to unit test a Go Gin handler function?

To test operations that involve the HTTP request, you have to actually initialize an *http.Request and set it to the Gin context. To specifically test c.BindQuery it’s enough to properly initialize the request’s URL and URL.RawQuery: func mockGin() (*gin.Context, *httptest.ResponseRecorder) { w := httptest.NewRecorder() c, _ := gin.CreateTestContext(w) // test request, must instantiate a request … Read more

How to test a spring controller method by using MockMvc?

You can use your applications dispatcher servlet xml using the following annoations. The following example is hitting a controller with the path /mysessiontest setting some session attributes and expecting a certain view to be returned: import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; … Read more

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