tdd

When unit testing, how should one handle testing the initialization of objects?

风流意气都作罢 提交于 2019-12-12 13:41:35
问题 So with most unit testing utilities I have come across, you usually get access to a SetUp() and TearDown() function of some sort. While I see that this comes in very handy for almost every unit test, I was wondering how testing the initialization of objects should be handled? I mean, in almost every other test, you would just let the SetUp() function handle it. However, in most of the basic testing utilities I have worked with, SetUp() gets called before every test. I have been wondering if

Django Forbidden HttpResponse in Test-Drive

。_饼干妹妹 提交于 2019-12-12 13:06:17
问题 I'm trying to get close to 100% test coverage and I've come across a 403 error in a test on Django-Admin features, as follows: class AdminTest(LiveServerTestCase): def setUp(self): self.client = Client() self.my_admin = User(username='user', is_staff=True) self.my_admin.set_password('password') self.my_admin.save() (...) def testCreatePost(self): self.client.get('/admin/', follow=True) loginResponse = self.client.login(username='user',password='password') self.assertTrue(loginResponse)

Reflection in unit tests for checking code coverage

泪湿孤枕 提交于 2019-12-12 12:03:08
问题 Here's the scenario. I have VO (Value Objects) or DTO objects that are just containers for data. When I take those and split them apart for saving into a DB that (for lots of reasons) doesn't map to the VO's elegantly, I want to test to see if each field is successfully being created in the database and successfully read back in to rebuild the VO. Is there a way I can test that my tests cover every field in the VO? I had an idea about using reflection to iterate through the fields of the VO's

Mock svn instance for testing svnkit tests

纵饮孤独 提交于 2019-12-12 11:51:33
问题 A project I'm working on interacts heavily with Subversion, using svnkit. Are there any examples on running a mock in-memory svn instance, to help facilitate testing etc? Cheers Marty 回答1: It's quite straightforward to create a temporary SVN repository on the filesystem to use during the test which you can delete immediately at the end of the test. You would use file:// protocol to access it. import static org.junit.Assert.*; import java.io.*; import org.apache.commons.io.FileUtils; import

TDD and Test Data

家住魔仙堡 提交于 2019-12-12 10:07:02
问题 I'm new to TDD and was wondering where to begin. I've read about as much as I think I can without throwing up and am still confused what to test and what not to test. For example, I know, from reading, we should not run tests against databases, thus enters the mocking framework. We mock our repositories so they will return fake data. My question is do we test requirements for data constants? For example, a requirement may state, a person should always have a name, thus: Assert.IsNotNull

How to unit test an extension method that calls html.EditorFor

梦想与她 提交于 2019-12-12 09:49:54
问题 During a spike, I created a nifty html helper extension method for use in my views, it worked well. It will make my views so much easier to maintain. Now I need to figure out how to unit test it. Here is the gist of what I am trying to do: public static MvcHtmlString EditorOrDisplayForBasedOnConvolutedBusinessLogic<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression) { if (ConvolutedBusinessLogic()) { return html.EditorFor(expression); } else { return

How to unit test Asp.net MVC fileUpload

老子叫甜甜 提交于 2019-12-12 08:35:35
问题 Hello I am new in TDD development. I came across this post for Using asp.net mvc to upload file Phil Haack states that a class could be used for file upload control, in which he use the default HttpFileCollectionValueProvider: [HttpPost] public ActionResult Index(HttpPostedFileBase file) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); file.SaveAs(path); } return RedirectToAction("Index");

how often should the entire suite of a system's unit tests be run?

倖福魔咒の 提交于 2019-12-12 08:28:54
问题 Generally, I'm still very much a unit testing neophyte. BTW, you may also see this question on other forums like xUnit.net, et cetera, because it's an important question to me. I apoligize in advance for my cross posting; your opinions are very important to me and not everyone in this forum belongs to the other forums too. I was looking at a large decade old legacy system which has had over 700 unit tests written recently (700 is just a small beginning). The tests happen to be written in

What is positive test and negative test in unit testing

依然范特西╮ 提交于 2019-12-12 07:44:36
问题 I'm pretty new to TDD. I see some docs says about positive test, negative test, boundary test etc. Can any one tell me the difference between a positive test and negative test? Is there any reference out there that says about the different types of tests? (I'm not looking for books) 回答1: Positive Testing - testing the system by giving the valid data. Negative Testing - testing the system by giving the Invalid data. For Example, an application contains a textbox and as per the user's

What javascript mocking frameworks are people using? [closed]

a 夏天 提交于 2019-12-12 07:29:43
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I'm using Jasmine for testing client & server side javascript and need to do some mocking. Has anyone got any suggestions for a good javascript mocking framework? 回答1: I tried this once, but ended up refactoring instead so it wasn't needed. It doesn't have dependencies, so it