tdd

How to unit-test an action, when return type is ActionResult?

为君一笑 提交于 2019-12-28 05:37:08
问题 I have written unit test for following action. [HttpPost] public ActionResult/*ViewResult*/ Create(MyViewModel vm) { if (ModelState.IsValid) { //Do something... return RedirectToAction("Index"); } return View(vm); } Test method can access Model properties, only when return type is ViewResult . In above code, I have used RedirectToAction so return type of this action can not be ViewResult . In such scenario how do you unit-test an action? 回答1: So here is my little example: public ActionResult

How do you mock a Sealed class?

痴心易碎 提交于 2019-12-28 01:51:27
问题 Mocking sealed classes can be quite a pain. I currently favor an Adapter pattern to handle this, but something about just keeps feels weird. So, What is the best way you mock sealed classes? Java answers are more than welcome . In fact, I would anticipate that the Java community has been dealing with this longer and has a great deal to offer. But here are some of the .NET opinions: Why Duck Typing Matters for C# Develoepers Creating wrappers for sealed and other types for mocking Unit tests

MVC3 & EF. Interface for TDD

房东的猫 提交于 2019-12-25 07:58:23
问题 Can somebody please explain: I am using MVC3/C#/Razor to build a project to get used to using MVC. I am using the inbuilt account controller. I am storing the account data in my local SQL database using Entity Framework to connect. How can I easily generate interfaces for EF? SO FAR I am using the plugin from: http://blog.johanneshoppe.de/2010/10/walkthrough-ado-net-unit-testable-repository-generator/#step1 This allows me to have an interface for my entities already created. However, I know

Detect test failures on jenkins

南楼画角 提交于 2019-12-25 07:52:59
问题 I have been playing around Jenkins since 5 days but I have a problem. I have a Java Code that has been unit tested with JUnit and I am using Gradle Build to build the code. I have deliberately tried to fail a test out of the three tests and gradle build reports a failure! which was expected. Yet I pushed my code onto github SampleTestProject and a build was triggered on Jenkins after a minute(as configured). Yet jenkins marks the build as successful even though the test was failed while

What to call test cases that are test integration with third-party services?

心已入冬 提交于 2019-12-25 04:25:19
问题 I have test cases, which make requests to real, not mocked, third-party services and verify that functions that handle responses are doing it correctly. I can't call them "functional", because they test only small pieces of code, that responsible to communication with third-party services. And I can't call them "unit" - because they hit real external services. What is correct name for them? 回答1: Those are called integration tests. Basically you have three types of tests: Unit tests, no

How to integrate AsMock into AsUnit 4?

大城市里の小女人 提交于 2019-12-25 03:31:02
问题 Trying to update AsMock mocking framework to v.1.0, and use it with AsUnit 4. But in runtime get a VerifyError (1153, inacceptible override) at the line with [RunWith("asmock.integration.asunit.ASMockRunner")] metatag in the test case class. I use FlashDevelop as an IDE. Have no idea, what's wrong. Could anyone help? 回答1: Have you added the includes line to the Flex Compiler arguments field within Eclipse/Flash Developer? You need to include -includes asmock.integration.asunit.ASMockRunner

How to Unit Test 'mkdir' function without file system access?

蹲街弑〆低调 提交于 2019-12-25 03:24:28
问题 I use py.test for unit testing. I have something just like this: Class Site(object): def set_path(self): """Checks if the blog folder exists. Creates new folder if necessary.""" if not os.path.isdir(self.user_dir): print "Creating new directory:", self.user_dir os.mkdir(self.user_dir) else: print "\n**", self.user, "directory already exists." How can I unit test this without touching the file system? Is there a general rule of thumb when dealing with such problems? I've thought about it for a

Hot Reload during Unit testing

淺唱寂寞╮ 提交于 2019-12-24 20:54:48
问题 I develop right now a small flutter app. I think as everyone, I fell in love with the hot reload feature. So now I'm wondering if there is any possibility to have the same developer experience during unit test. Do have to turn a flag somewhere or is it right know just no possible. If is not possible, are there any plans to make it possible? 回答1: I guess what you want is to run the new tests as soon as they changed. But in that case it's not a hot reload. Simply a watcher that detect whenever

Integration Testing with a fake server

天涯浪子 提交于 2019-12-24 17:26:02
问题 I have a service which connects to a set of api's which i want to test. I would like to make a Fake Service for my integration tests (to simulate failure situations) I cannot simply use @RestController as they are not loaded during a test, and I looked into mockserver but I am unsure if it is what I am looking for, as I do not want my test to trigger a mock call, but rather my code should trigger the api call normally, simply using the mock server rather than an actual server (the base url is

Database base unit testing strategy: truncating tables between unit tests & test data

那年仲夏 提交于 2019-12-24 14:45:44
问题 I'm attempting to use JUnit to test some database code. I'm pretty new to this so please bear with me. I have a local test database which consists of four tables. Two of these tables are populated with data and the other two are empty before the program executes. The program basically performs some queries on the two tables which are populated, processes the results then writes those results to the two tables which are empty when the program is executed. There are a number of methods which