2

I feel like I'm stuck in this political/religious battle. From the research I've done I've found that many people believe very strongly that UI testing is silly to do via unit testing and is something much better done by an actual person. I agree.

However it seems the higher-ups have told me to unit test the UI. (Which is already strange since they had previously told me I only had to write a test plan and not actual test). In all sincerity I'm not very familiar with unit testing. I'm trying to use MOQ but all the tutorials I find for it use repositories and not services and I'm structuring my web application around services.

As an example here is (a part of) a service:

public class ProductService : Service<Product, EntitiesDbContext>
    {
        ...
        public Product GetProduct(int id)
        {
            return All().FirstOrDefault(p => p.ProductId == id);
        }
        ...
    }

My assumption is that I need to create let's say, a new Product using Moq, and then someone validate the hard-coded input using my model. I'm not sure how to do this.

Testing the UI is the bulk of my work as the website relies heavily on user input via forms. Again I find it quite silly to test with unit testing since my models are very strict and only allow certain inputs.

To my question: How would I go about testing form input using MOQ or possibly another testing framework? I've heard that there are programs out there that can track your actions and then replicate them, but I've been unsuccessful in finding them and I also believe that such a technology would cost money.

5 Answers 5

2

Try Selenium or Watin for UI testing.

Sign up to request clarification or add additional context in comments.

Comments

1

Visual Studio 2010 Ultimate has something called Coded UI test. Basically, you record your actions in Internet Explorer, which translate to C# code where you add assertions, and then you replay the actions in different browsers.

However, it is very difficult to test against a database backed web application, since you can hardly figure out which is the newly added row. To simplify matters, you might want to set up a sample database which will be reset to its initial state before running your test suite in sequence.

Take a look at the various TechEd videos on how to use Coded UI Test. E.g. http://www.youtube.com/watch?v=rZ8Q5EJ2bQM

Comments

1

Are you testing the Actions for your UI or are you testing Actual UI.

If you are testing the Actions and what data they are sending to the view then doing unit tests using something like NUnit, xUnit, etc and using a moq framework like MOQ or Rhino Mocks would be the right thing to do.

if you are testing the Actual UI(the HTML returned by the web server) then using an automated testing framework like Selenium would be the right tool

Comments

1

You can also try Ivonna (http://ivonna.biz) for MVC testing -- doesn't test your client side, but lets you test your Asp.Net server side code.

But first of all you should ask yourself (or your management) a question: what do I want to test? Client/server side validation? Your Service? Action Method?

Comments

1

There is a lot of opposition by developers to automate testing of the UI. What I did years ago was use "Selenium Core" This allowed me to fix do the testing in Firefox, then save out as C# , and then have a blend of C# and Html files in which I could have it do the following.

  1. Forgot Password -- Automation random usernames from database would be entered and then encrypted passwords were emailed to various gmail accounts I set up and I had C# API to login to gmail and retrieve new reset password, then redirect and have application enter new password , and I could put this on a CI Server Hudson and automate this testing all day long, and logging of success and errors etc...

  2. New Registration... similar to #1

So for your UI testing, lets call that Functional or UAT testing ... Then for true Unit Testing, this is for NUnit / Xunit, MSTest etc... , and then MOQ etc... can assist. Integration testing is truly testing of the entire application with connected systems... like a file system or WCF or Database , not being "mocked"

They all have their pros and cons and none of it is perfect, but most people end up saying Unit Testing is most bang for the buck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.