integration-testing

Making real requests to HTTP server in AngularJS unit/integration tests

柔情痞子 提交于 2019-11-30 08:46:20
问题 Making a request that wasn't mocked with $httpBackend.when in Angular 1.x unit/integration test results in an error: Error: Unexpected request: GET /real-request Is it possible to make real HTTP requests with ngMock and Karma+Jasmine test rig? What is a good practice to do that? 回答1: AngularJS is opinionated framework, and its opinion on HTTP requests in unit tests is that all of them should be mocked. It is not advisable to do real HTTP requests in unit tests for two reasons. Unit tests are

Spring MockRestServiceServer handling multiple requests to the same URI (auto-discovery)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 08:25:02
Let's say I am writing Spring integration tests for a REST service A. This service in turn hits another REST service B and gets a list of URIs to hit on REST service C. It is kind of auto-discovery pattern. I want to mock B and C responses using MockRestServiceServer. Now the response from B is a list of URIs, they are all very similar, and for the sake of the example lets say my response from B is like so: { uris: ["/stuff/1.json", "/stuff/2.json", "/stuff/39.json", "/stuff/47.json"] } Simply service A will append each of them onto base URL for service C and make those requests. Mocking B is

Spring: unit and integration tests

跟風遠走 提交于 2019-11-30 07:13:54
I'm looking for best practices for setting up unit and integration tests using Spring. I usually use 3 kind of tests: "real" unit tests (no dependencies) tests run either as "unit" test (in-memory db, local calls, mock objects,...) or as integration test (persistent db, remote calls,...) tests run only as integration tests Currently I only have tests of the second category, which is the tricky part. I set-up a base test class like: @ContextConfiguration(locations = { "/my_spring_test.xml" }) public abstract class AbstractMyTestCase extends AbstractJUnit4SpringContextTests And "unit" tests like

Code coverage for Protractor tests in AngularJS

跟風遠走 提交于 2019-11-30 07:07:07
I am running some e2e tests in my angularJS app with protractor (as recommended in the angularJS documentation). I've googled around and cannot find any information on how to measure coverage for my protractor tests. I think I'm missing something here... is there any way to get a code coverage report for protractor e2e tests? Or is it simply a feature for unit tests? This is achievable using Istanbul . Here is the process, with some example configurations that I've extracted from our project (not tested): Instrument your code using the command istanbul instrument . Make sure that istanbul's

Cucumber and Capybara, clicking a non-link or button element

杀马特。学长 韩版系。学妹 提交于 2019-11-30 06:21:35
问题 I am trying to test an inplace editor using Cucumber/Capybara/Selenium stack, but my problem is that the editor is activated by clicking a div and not a link or button. I can not seem to figure out how to get Capybara to do this. Is there a way of doing this? 回答1: You can click on an element via Capybara::Element.click. I add the following for this in my web_steps.rb to click on divs. When /^(?:|I )click within "([^"]*)"$/ do |selector| find(selector).click end There is also Element.trigger(

Can I make an object public for integration tests and/or benchmarks only?

白昼怎懂夜的黑 提交于 2019-11-30 06:05:11
问题 As suggested by The Book, I have moved the integration tests in my crate to a tests directory. Some of those tests use functions that I don't want to export outside of the crate, though, and I am no longer able to use them in the integration test folder. I use them for non-test purposes too, so they need to compile outside of tests too . I tried using variants of pub(restricted), but I wasn't able to make it work. Ideally I'd like to have something like pub(tests) . directory tree (the

How to order methods of execution using Visual Studio to do integration testing?

强颜欢笑 提交于 2019-11-30 04:49:20
I have 2 questions in regard doing integration testing using VS 2010 First, I'm really in need of finding a way to execute these testing methods in the order I want them to. Note: I know in Unit Testing, methods should run standalone from anything else, but these are integration tests which I do depend on the order of which method runs first. On the same note, is there a way to keep a local variable through running the tests? For example like the following code which right now fails. [TestClass] public class UnitTest1 { int i = 0; [TestMethod] public void TestMethod1() { i = 5; } [TestMethod]

“Could not find a valid mapping for #<User …>” only on second and successive tests

蓝咒 提交于 2019-11-30 04:29:55
I'm trying to write a request test that asserts that the proper links appear on the application layout depending in whether a user is logged in or out. FWIW, I'm using Devise for the authentication piece. Here's my spec: require 'spec_helper' require 'devise/test_helpers' describe "Layout Links" do context "the home page" do context "session controls" do context "for an authenticated user" do before do # I know these should all operate in isolation, but I # want to make sure the user is explicitly logged out visit destroy_user_session_path @user = Factory(:user, :password => "Asd123",

Integration Testing POSTing an entire object to Spring MVC controller

我的未来我决定 提交于 2019-11-30 04:10:27
Is there a way to pass an entire form object on mock request when integration testing a spring mvc web app? All I can find is to pass each field separately as a param like this: mockMvc.perform(post("/somehwere/new").param("items[0].value","value")); Which is fine for small forms. But what if my posted object gets larger? Also it makes the test code look nicer if I can just post an entire object. Specifically I'd like to test the selection of multiple items by checkbox and then posting them. Of course I could just test posting a single item, but I was wondering.. We're using spring 3.2.2 with

Does the new Spring MVC Test Framework released in Spring 3.2 test the web.xml configuration?

笑着哭i 提交于 2019-11-30 04:00:07
I've read the docs ( http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/testing.html#spring-mvc-test-framework ) several times and I can't confirm if the WebApplicationContext context that gets injected when you use the @WebApplicationContext annotation is actually looking at the web.xml. In other words, I want to test my web.xml configuration. The filters and servlet path specifically. But when I configure my test it ignores the web.xml. (e.g. I try a get request on a URL like this /myServletPath/foo and it fails with a 404.) My test: @RunWith