Search Results

Search found 10206 results on 409 pages for 'tooling and testing'.

Page 25/409 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Testing a scoped find in a Rails controller with RSpec

    - by Joseph DelCioppio
    I've got a controller called SolutionsController whose index action is different depending on the value of params[:user_id]. If its nil, then it simply displays all of the solutions on my site, but if its not nil, then it displays all of the solutions for the given user id. Here it is: def index if(params[:user_id]) @solutions = @user.solutions.find(:all) else @solutions = Solution.find(:all) end end and @user is determined like this: private def load_user if(params[:user_id ]) @user = User.find(params[:user_id]) end end I've got an Rspec test to test the index action if the user is nil: describe "GET index" do context "when user_id is nil" do it "should find all of the solutions" do Solution.should_receive(:find).with(:all).and_return(@solutions) get :index end end end however, can someone tell me how I write a similar test for the other half of my controller, when the user id isn't nil? Something like: describe "GET index" do context "when user_id isn't nil" do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :user => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions).and_return(@solutions) get :index, :user_id => @user.id end end end But that doesn't work. Can someone help me out? Joe

    Read the article

  • appengine local datastore integration testing with spring

    - by mirror303
    Hi all, I want to write some integration tests to see how my spring-managed DAO's behave when talking to the appengine datastore. Following the spring manual I will be providing my test-classes with the proper annotations: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) After a lot of browsing I found this blog post dating back to august '09 from somebody doing exactly what I want to achieve. It involves writing a TestEnvironment class that implements ApiProxy.Environment plus talking to ApiProxyLocalImpl. However, if I look at the current docs (for version 1.3.1), it seems that this has been replaced by newing an instance of the framework provided LocalDatastoreServiceTestConfig which is passed to a LocalServiceTestHelper. It is too bad that the appengine docs don't show an example how to do this with JPA because then the spring wiring would be trivial. Trying to follow the route outlined in the blog posting has me running into a compiler messages telling me that classes such as ApiProxyLocalImpl are not visible by me. Hence, there must be a new way of doing it, which probably involves the LocalServiceTestHelper. My question: Does anybody know how? I know I will need to configure an EntityManagerFactory and provide it with the Datastore connection somehow... but how? :)

    Read the article

  • Unit testing JSON output module, best practices

    - by Banang
    I am currently working on a module that takes one of our business objects and returns a json representation of that object to the caller. Due to limitations in our environment I am unable to use any existing json writer, so I have written my own, which is then used by the business object writer to serialize my objects. The json writer is tested in a way similar to this @Test public void writeEmptyArrayTest() { String expected = "[ ]"; writer.array().endArray(); assertEquals(expected, writer.toString()); } which is only manageable because of the small output each instruction produces, even though I keep feeling there must be a better way. The problem I am now facing is writing tests for the object writer module, where the output is much larger and much less manageable. The risk of spelling mistakes in the expected strings mucking up my tests seem too great, and writing code in this fashion seems both silly and unmanageable in a long term perspective. I keep feeling like I want to write tests to ensure that my tests are behaving correctly, and this feeling worries me. Therefore, is there a better way of doing this? Surely there must be? Does anyone know of any good literature in regard to this specific case (doesn't have to be json, but you know what I mean)? Grateful for all help.

    Read the article

  • Easiest way of unit testing C code with Python

    - by Jon Mills
    I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it? Some ideas include: Wrapping the code as a Python C extension using the Python API Wrap the C code using SWIG Add a DLL wrapper to the C code and load it into Python using ctypes Add a small XML-RPC server to the c-code and call it using xmlrpclib (yes, I know this seems a bit far-out!) Is there a canonical way of doing this? I'm going to be doing this quite a lot, with different C modules, so I'd like to find a way which is least effort.

    Read the article

  • Testing a command from Perl and checking content of a file

    - by justintime
    I want to test a script I have written in Perl and specifically check what output it writes to file. I wrote it some time ago and don't want to modify it to the extent of turning it into a module but would like to regression test it before adding some small functional changes. So far I have use Test::Command tests = 10; exit_is_num($cmd, 0); .... But the command produces some files and I want to check those files are the same as I expect (either equal or match some regexp). Any suggestions

    Read the article

  • Choosing an automated testing tool

    - by pal25
    My project is compatible only with Internet Explorer. I want the test scripts to get generated automatically as it is done in Selenium IDE. Can i use Selenium RC to test my application? I could not use Selenium IDE as it can be used only with Mozilla Firefox.

    Read the article

  • Selenium Testing

    - by Joakim
    Hi I want to get a bunch of dom-objects with xpath and loop through those to check if they contains a specified text, is this possible in the Selenium IDE or rc? Perl is my prefered language XPath would be something like xpath=//tbody[@class='table-data']/tr/td/div[@class='table-item'] This would return all row items in the table, but i need to check each div if contains a specified text string. Is this possible with Selenium? Best regards

    Read the article

  • Java Junit testing problem

    - by agazerboy
    Hi All, I am using Junit 4. My whole program is working fine. I am trying to write a test case. But there is one error... here is very basic sample test public class di extends TestCase{ private static Records testRec; public void testAbc() { Assert.assertTrue( "There should be some thing.", di.testRec.getEmployee() > 0); } } and when i run this it give me error that fName can not be null if i use super and do like this public TestAgnes() { super("testAbc"); } it work all fine. It wasn't this before with JUnit 3.X am I doing wrong or they changed it :( Sorry if I am not clear Is there any way to executre test without super? or calling functions etc. ?

    Read the article

  • Testing a method that sends e-mail without sending the mail

    - by SnOrfus
    I have a method like public abstract class Base { public void MethodUnderTest(); } public class ClassUnderTest : Base { public override MethodUnderTest() { if(condition) { IMail mail = new Mail() { /* ... */ }; IMailer mailer = new Mailer() { /* ... */ } mailer.Send(mail); } else { /* ... */ } } } I have unit tests for this method, and the mail gets sent to myself, so it's not terrible (better than no test) but I'd prefer not to send the mail. The problem I have is that I don't want test specific code in the class (ie. if (testMode) return; instead of sending the mail) I don't know lots about DI, but I considered passing a mock IMailer into MethodUnderTest except that it overrides the base class, and no other class that derives from Base needs an IMailer object (I don't want to force implementers of Base to take an unnecessary IMailer in MethodUnderTest) What else can I do? (note: IMail and IMailer are part of an external library for sending e-mail. It's written in house, so I can modify it all I like if necessary, though I can't see a need to in this situation)

    Read the article

  • Unit Testing Refcounted Critical Section Class

    - by BillyONeal
    Hello all :) I'm looking at a simple class I have to manage critical sections and locks, and I'd like to cover this with test cases. Does this make sense, and how would one go about doing it? It's difficult because the only way to verify the class works is to setup very complicated threading scenarios, and even then there's not a good way to test for a leak of a Critical Section in Win32. Is there a more direct way to make sure it's working correctly? Here's the code: CriticalSection.hpp: #pragma once #include <windows.h> namespace WindowsAPI { namespace Threading { class CriticalSection; class CriticalLock { std::size_t *instanceCount; CRITICAL_SECTION * criticalStructure; bool lockValid; friend class CriticalSection; CriticalLock(std::size_t *, CRITICAL_SECTION *, bool); public: bool IsValid() { return lockValid; }; void Unlock(); ~CriticalLock() { Unlock(); }; }; class CriticalSection { std::size_t *instanceCount; CRITICAL_SECTION * criticalStructure; public: CriticalSection(); CriticalSection(const CriticalSection&); CriticalSection& operator=(const CriticalSection&); CriticalSection& swap(CriticalSection&); ~CriticalSection(); CriticalLock Enter(); CriticalLock TryEnter(); }; }} CriticalSection.cpp: #include "CriticalSection.hpp" namespace WindowsAPI { namespace Threading { CriticalSection::CriticalSection() { criticalStructure = new CRITICAL_SECTION; instanceCount = new std::size_t; *instanceCount = 1; InitializeCriticalSection(criticalStructure); } CriticalSection::CriticalSection(const CriticalSection& other) { criticalStructure = other.criticalStructure; instanceCount = other.instanceCount; instanceCount++; } CriticalSection& CriticalSection::operator=(const CriticalSection& other) { CriticalSection copyOfOther(other); swap(copyOfOther); return *this; } CriticalSection& CriticalSection::swap(CriticalSection& other) { std::swap(other.instanceCount, instanceCount); std::swap(other.criticalStructure, other.criticalStructure); return *this; } CriticalSection::~CriticalSection() { if (!--(*instanceCount)) { DeleteCriticalSection(criticalStructure); delete criticalStructure; delete instanceCount; } } CriticalLock CriticalSection::Enter() { EnterCriticalSection(criticalStructure); (*instanceCount)++; return CriticalLock(instanceCount, criticalStructure, true); } CriticalLock CriticalSection::TryEnter() { bool lockAquired; if (TryEnterCriticalSection(criticalStructure)) { (*instanceCount)++; lockAquired = true; } else lockAquired = false; return CriticalLock(instanceCount, criticalStructure, lockAquired); } void CriticalLock::Unlock() { if (!lockValid) return; LeaveCriticalSection(criticalStructure); lockValid = false; if (!--(*instanceCount)) { DeleteCriticalSection(criticalStructure); delete criticalStructure; delete instanceCount; } } }}

    Read the article

  • Unit Testing in QTestLib - running single test / tests in class / all tests

    - by Dave
    I'm just starting to use QTestLib. I have gone through the manual and tutorial. Although I understand how to create tests, I'm just not getting how to make those tests convenient to run. My unit test background is NUnit and MSTest. In those environments, it was trivial (using a GUI, at least) to alternate between running a single test, or all tests in a single test class, or all tests in the entire project, just by clicking the right button. All I'm seeing in QTestLib is either you use the QTEST_MAIN macro to run the tests in a single class, then compile and test each file separately; or use QTest::qExec() in main() to define which objects to test, and then manually change that and recompile when you want to add/remove test classes. I'm sure I'm missing something. I'd like to be able to easily: Run a single test method Run the tests in an entire class Run all tests Any of those would call the appropriate setup / teardown functions.

    Read the article

  • Unit Testing a Django Form with a FileField

    - by Jason Christa
    I have a form like: #forms.py from django import forms class MyForm(forms.Form): title = forms.CharField() file = forms.FileField() #tests.py from django.test import TestCase from forms import MyForm class FormTestCase(TestCase) def test_form(self): upload_file = open('path/to/file', 'r') post_dict = {'title': 'Test Title'} file_dict = {} #?????? form = MyForm(post_dict, file_dict) self.assertTrue(form.is_valid()) How do I construct the *file_dict* to pass *upload_file* to the form?

    Read the article

  • Python Pre-testing for exceptions when coverage fails

    - by Tal Weiss
    I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in the official docs). I have very extensive unit tests and I regularly check coverage to avoid surprises like this. I also use Pylint (everything is integrated in PyDev) and I never ignore warnings, yet I failed to catch this bug before my users did. Is there anything I can change in my methodology to avoid these kind of runtime errors? (which would have been caught at compile time in Java / C#?). I'm looking for something more than wrapping my code with a big try-except. What else can I do? How many other build in Python functions are hiding nasty surprises like this???

    Read the article

  • testing dao with hibernate genericdao pattern with spring.Headache

    - by black sensei
    Hello good fellas! in my journey of learning hibernate i came across an article on hibernate site. i' learning spring too and wanted to do certain things to discover the flexibility of spring by letting you implement you own session.yes i don't want to use the hibernateTemplate(for experiment). and i'm now having a problem and even the test class.I followed the article on the hibernate site especially the section an "implementation with hibernate" so we have the generic dao interface : public interface GenericDAO<T, ID extends Serializable> { T findById(ID id, boolean lock); List<T> findAll(); List<T> findByExample(T exampleInstance); T makePersistent(T entity); void makeTransient(T entity); } it's implementation in an abstract class that is the same as the one on the web site.Please refer to it from the link i provide.i'll like to save this post to be too long now come my dao's messagedao interface package com.project.core.dao; import com.project.core.model.MessageDetails; import java.util.List; public interface MessageDAO extends GenericDAO<MessageDetails, Long>{ //Message class is on of my pojo public List<Message> GetAllByStatus(String status); } its implementation is messagedaoimpl: public class MessageDAOImpl extends GenericDAOImpl <Message, Long> implements MessageDAO { // mySContainer is an interface which my HibernateUtils implement mySContainer sessionManager; /** * */ public MessageDAOImpl(){} /** * * @param sessionManager */ public MessageDAOImpl(HibernateUtils sessionManager){ this.sessionManager = sessionManager; } //........ plus other methods } here is my HibernatUtils public class HibernateUtils implements SessionContainer { private final SessionFactory sessionFactory; private Session session; public HibernateUtils() { this.sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } public HibernateUtils(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } /** * * this is the function that return a session.So i'm free to implements any type of session in here. */ public Session requestSession() { // if (session != null || session.isOpen()) { // return session; // } else { session = sessionFactory.openSession(); // } return session; } } So in my understanding while using spring(will provide the conf), i'ld wire sessionFactory to my HiberbernateUtils and then wire its method RequestSession to the Session Property of the GenericDAOImpl (the one from the link provided). here is my spring config core.xml <bean id="sessionManager" class="com.project.core.dao.hibernate.HibernateUtils"> <constructor-arg ref="sessionFactory" /> </bean> <bean id="messageDao" class="com.project.core.dao.hibernate.MessageDAOImpl"> <constructor-arg ref="sessionManager"/> </bean> <bean id="genericDAOimpl" class="com.project.core.dao.GenericDAO"> <property name="session" ref="mySession"/> </bean> <bean id="mySession" factory-bean="com.project.core.dao.SessionContainer" factory-method="requestSession"/> now my test is this public class MessageDetailsDAOImplTest extends AbstractDependencyInjectionSpringContextTests{ HibernateUtils sessionManager = (HibernateUtils) applicationContext.getBean("sessionManager"); MessageDAO messagedao =(MessageDAO) applicationContext.getBean("messageDao"); static Message[] message = new Message[] { new Message("text",1,"test for dummies 1","1234567890","Pending",new Date()), new Message("text",2,"test for dummies 2","334455669990","Delivered",new Date()) }; public MessageDAOImplTest() { } @Override protected String[] getConfigLocations(){ return new String[]{"file:src/main/resources/core.xml"}; } @Test public void testMakePersistent() { System.out.println("MakePersistent"); messagedao.makePersistent(message[0]); Session session = sessionManager.RequestSession(); session.beginTransaction(); MessageDetails fromdb = ( Message) session.load(Message.class, message[0].getMessageId()); assertEquals(fromdb.getMessageId(), message[0].getMessageId()); assertEquals(fromdb.getDateSent(),message.getDateSent()); assertEquals(fromdb.getGlobalStatus(),message.getGlobalStatus()); assertEquals(fromdb.getNumberOfPages(),message.getNumberOfPages()); } i'm having this error exception in constructor testMakePersistent(java.lang.NullPointerException at com.project.core.dao.hibernate.MessageDAOImplTest) with this stack : at com.project.core.dao.hibernate.MessageDAOImplTest.(MessageDAOImplTest.java:28) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at junit.framework.TestSuite.createTest(TestSuite.java:61) at junit.framework.TestSuite.addTestMethod(TestSuite.java:283) at junit.framework.TestSuite.(TestSuite.java:146) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:481) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1031) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:888) )) How to actually make this one work.I know this is a lot to stuffs and i'm thanking you for reading it.Please give me a solution.How would you do this? thanks

    Read the article

  • Unit Testing in ASP.NET MVC: Minimising the number of asserts per test

    - by Neil Barnwell
    I'm trying out TDD on a greenfield hobby app in ASP.NET MVC, and have started to get test methods such as the following: [Test] public void Index_GetRequest_ShouldReturnPopulatedIndexViewModel() { var controller = new EmployeeController(); controller.EmployeeService = GetPrePopulatedEmployeeService(); var actionResult = (ViewResult)controller.Index(); var employeeIndexViewModel = (EmployeeIndexViewModel)actionResult.ViewData.Model; EmployeeDetailsViewModel employeeViewModel = employeeIndexViewModel.Items[0]; Assert.AreEqual(1, employeeViewModel.ID); Assert.AreEqual("Neil Barnwell", employeeViewModel.Name); Assert.AreEqual("ABC123", employeeViewModel.PayrollNumber); } Now I'm aware that ideally tests will only have one Assert.xxx() call, but does that mean I should refactor the above to separate tests with names such as: Index_GetRequest_ShouldReturnPopulatedIndexViewModelWithCorrectID Index_GetRequest_ShouldReturnPopulatedIndexViewModelWithCorrectName Index_GetRequest_ShouldReturnPopulatedIndexViewModelWithCorrectPayrollNumber ...where the majority of the test is duplicated code (which therefore is being tested more than once and violates the "keep tests fast" advice)? That seems to be taking it to the extreme to me, so if I'm right as I am, what is the real-world meaning of the "one assert per test" advice?

    Read the article

  • Django TestCase testing order

    - by ziang
    If there are several methods in the test class, I found that the order to execute is alphabetical. But I want to customize the order of execution. How to define the execution order? For example: testTestA will be loaded first than testTestB. class Test(TestCase): def setUp(self): ... def testTestB(self): #test code def testTestA(self): #test code

    Read the article

  • Integration testing - Hibernate & DbUnit

    - by Marco
    Hi, I'm writing some integrations tests in JUnit. What happens here is that when i run all the tests together in a row (and not separately), the data persisted in the database always changes and the tests find unexpected data (inserted by the previous test) during their execution. I was thinking to use DbUnit, but i wonder if it resets the auto-increment index between each execution or not (because the tests also check the IDs of the persisted entities). Thanks M.

    Read the article

  • Testing bash scripts

    - by nimcap
    We have a system that has some bash scripts running besides Java code. Since we are trying to "Test Everything That Could Possibly Break" and those bash scripts may break, we want to test them. The problem is it is hard to test the scripts. Is there a way or a best practice to test bash scripts? Or should we quit using bash scripts and look for alternative solutions that are testable?

    Read the article

  • Unit Testing Hibernate's Optimistic Locking (within Spring)

    - by Michal Bachman
    I'd like to write a unit test to verify that optimistic locking is properly set up (using Spring and Hibernate). I'd like to have the test class extend Spring's AbstractTransactionalJUnit4SpringContextTests. What I want to end up with is a method like this: @Test (expected = StaleObjectStateException.class) public void testOptimisticLocking() { A a = getCurrentSession().load(A.class, 1); a.setVersion(a.getVersion()-1); getCurrentSession().saveOrUpdate(a); getCurrentSession().flush(); fail("Optimistic locking does not work"); } This test fails. What do you recommend as a best practice? The reason I am trying to do this is that I want to transfer the version to the client (using a DTO). I want to prove that when the DTO is sent back to the server and merged with a freshly loaded entity, saving that entity will fail if it's been updated by somebody else in the meantime.

    Read the article

  • Unit Testing: DateTime.Now

    - by Pedro
    I have some unit tests that expects the 'current time' to be different than DateTime.Now and I don't want to change the computer's time, obviously. What's the best strategy to achieve this? Thanks

    Read the article

  • Robotium Uniting Testing on an application having multiple processes

    - by warenix
    I have written an application running activities in multiple processes. I tried Robotium by creating a new test project set target package to my application. When I executed it, the test stopped with the following error message: Error in testDisplayBlackBox: java.lang.RuntimeException: Intent in process com.abc.def resolved to different process com.abc.def:mail: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.abc.def/com.abc.def.email.activity.Welcome } at android.app.Instrumentation.startActivitySync(Instrumentation.java:377) at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119) at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97) at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104) at com.abc.def.test.TestApk.setUp(TestApk.java:31) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584) Test results for InstrumentationTestRunner=.E Time: 0.027 FAILURES!!! Tests run: 1, Failures: 0, Errors: 1 Is it possible to have any workaround provided that I have source code in hand?

    Read the article

  • dummy IVR for testing vxml

    - by Nippysaurus
    Voxeo provide a free IVR for development purposes, but I was wondering if there is a much simpler form of test IVR, perhaps which runs on the local machine and uses your microphone and speakers instead of the telephony network?

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >