testing

unit testing with in-memory database [duplicate]

让人想犯罪 __ 提交于 2019-12-23 09:33:58
问题 This question already has answers here : Running PostgreSQL in memory only (7 answers) Closed 5 years ago . I have PostgreSQL database. It is used for unit testing. I want to speed the tests up so I want to use some kind of in-memory databases (e.g. H2). I want to dump the database (from PostgreSQL) and the import such a dump into in-memory database. Do you have any suggestion concerning in-memory database choice? I want that database to be compatible with PostgreSQL. 回答1: I'd simply create a

Get environment inside controller

ⅰ亾dé卋堺 提交于 2019-12-23 09:33:06
问题 I have a situation in one of my controllers that should only be accessed via AJAX, I have the following code. if (!$request->isXmlHttpRequest()) { $response = new Response(); $response->setContent('AJAX requests only!'); return $response; } When I am testing this gives me an issue because the request hasn't actually been made via AJAX. This then breaks my tests every time. How should I go about working around this? My Ideas: I have tried to set a server header but have had absolutely no

Why should you avoid conditional logic in unit tests and how? [closed]

老子叫甜甜 提交于 2019-12-23 09:30:12
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . Imagine having the following classes: public class Product { private String name; private double price; // Constructors, getters and setters } public class Products { private List<Product> products; // CRUD methods public double getTotalPrice() { // calculates the price of all products } } I have

Nunit Testing MVC Site

余生长醉 提交于 2019-12-23 09:29:31
问题 I've run into a bit of an issue trying to unit test an MVC site I have: I require a lot of the ASP.NET environment to be running (generation of httpcontexts, sessions, cookies, memberships, etc.) to fully test everything. Even to test some of the less front end stuff needs memberships in order to properly work, and it's been finicky to get this all spoofed by hand. Is there a way to spin up an application pool inside of NUnit tests? That seems like the easiest way. 回答1: I'm not aware of a way

Hamcrest generics hell #2 : iterableWithSize gives errror “is not applicable for the arguments”

和自甴很熟 提交于 2019-12-23 09:27:07
问题 In hamcrest (1.3.RC2, with no JUnit dependencies) I am failing using iterableWithSize(). I have an (extension of) an Iterator parametrized with Content like this EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*"); where EndResult is package org.springframework.data.neo4j.conversion; public interface EndResult<R> extends Iterable<R> {...} and Content is a my Pojo. Now, I would think that this would work assertThat(contents, iterableWithSize(1)); but it

Mock Build Version with Mockito

为君一笑 提交于 2019-12-23 09:26:44
问题 My target is to mock Build.Version.SDK_INT with Mockito. Already tried: final Build.VERSION buildVersion = Mockito.mock(Build.VERSION.class); doReturn(buildVersion.getClass()).when(buildVersion).getClass(); doReturn(16).when(buildVersion.SDK_INT); Problem is that: when requires method after mock, and .SDK_INT is not a method. 回答1: So far from other questions similar to this one it looks like you have to use reflection. Stub value of Build.VERSION.SDK_INT in Local Unit Test How to mock a

Test framework allowing tests to depend on other tests

断了今生、忘了曾经 提交于 2019-12-23 09:15:48
问题 I'm wondering if there is a test framework that allows for tests to be declared as being dependent on other tests. This would imply that they should not be run, or that their results should not be prominently displayed, if the tests that they depend on do not pass. The point of such a setup would be to allow the root cause to be more readily determined in a situation where there are many test failures. As a bonus, it would be great if there some way to use an object created with one test as a

Check if any tests raise a deprecation warning with pytest

杀马特。学长 韩版系。学妹 提交于 2019-12-23 09:15:44
问题 I am using pytest to run tests in a Python package, and I would like to know if any of the code that is executed as part of the tests is raising deprecation warnings (when all tests are passing). Does anyone know of a way to do this? 回答1: The code import warnings warnings.simplefilter("error") will turn (all) warnings into errors, which may help. Alternatively, you can get a list of generated warnings with import warnings with warnings.catch_warnings(record=True) as w: warnings.warn(

Nunit runs each test twice

徘徊边缘 提交于 2019-12-23 09:15:26
问题 I encounter a problem running my tests via NUnit. I dont know why but each test runs twice. The point is that on another laptop it normally runs only one time. Have anyone the same problem and know how to deal with it? 回答1: I had the same problem. In my case, I had both the Visual Studio extension and the NuGet package of the NUnit Test Runner installed. It seems they were both executing the tests, resulting in tests being run twice. Uninstalling the Visual Studio extension solved the issue.

Fixtures with Paperclip

巧了我就是萌 提交于 2019-12-23 08:57:19
问题 I'm using Paperclip to store documents, but I can't find how to create fixtures of them, I wrote this : <% doc = Document.create(:asset => File.open(Rails.root.join('spec', 'assets', 'image.png'))) %> <%= part_event_image %>: asset_file_name: <%= doc.asset_file_name %> asset_content_type: <%= doc.asset_content_type %> asset_file_size: <%= doc.asset_file_size %> asset_updated_at: <%= doc.asset_updated_at %> documentable: party (Event) %> <% end %> But one I ran it, the document exist in the