Code Generation

Mar 5, 2010 at 11:30 AM
Edited Mar 5, 2010 at 12:00 PM

As an idea for moving forward, it would be great to expand upon the WPF app.

The StoryQ converts method names into report string. It would be cool if it could change a written story entry into fully generated code so a developer need only fill the blanks. For example:

Story is Data Safety
In order to Keep my data safe
As a User
I want All credit card numbers to be encrypted
With scenario submitting shopping cart
Given I have typed my credit card number into the checkout page
When I click the buy button
And the browser posts my credit card number over the internet
Then the form should be posted over https

Generates to:

using **any namespaces we need, nunit, storyq etc...**

public namespace DataSafetyTests
{
    [TestFixture]
    public class SubmittingShoppingCartTests
    {
        private Scenario _scenario;

        [SetUp]
        public void SetUp()
        {
            _scenario = new Story("Data Safety")
                .InOrderTo("Keep my data safe")
                .AsA("User")
                .IWant("All credit card numbers to be encrypted")
                .WithScenario("submitting shopping cart")
        }

        [Test]
public void WhenIClickTheBuyButton_ThenTheFormShouldBePostedOverHttps() { _scenario .Given(IHaveTypedMyCreditCardNumberIntoTheCheckoutPage) .When(IClickTheBuyButton) .And(TheBrowserPostsMyCreditCardNumberOverTheInternet) .Then(TheFormShouldBePostedOverHttps) } private void IHaveTypedMyCreditCardNumberIntoTheCheckoutPage() { throw new NotImplementedException(); }
      private void IClickTheBuyButton()
{
throw new NotImplementedException();
}
...and so on
} }

So basically some form of templating system, whereby we can specify the Testing Framework we're using (in my case NUnit).

And similar to how method names are parsed, we can apply how we want the code to be generated.

Thoughts?

Coordinator
Mar 5, 2010 at 12:31 PM

The first version of StoryQ's converter UI  generated a bit more boilerplate than the current version does. I definitely want the converter UI to generate more useful code for you than it currently does, and one of the things I had in mind was that when you typed a story with /[^a-zA-Z_]/ text in it, it would generate a method stub with an appropriate method formatter attribute.

Currently, I can think of the following problems with generating so much boilerplate:

  • Resharper or VS can do a lot of the step method generation for you (ok, it's a few more keypresses!)
  • Often you might be adding or changing a small part of the test class, not the whole thing, so to have the whole thing regenerated would be problematic
  • People would want a high degree of control over what gets generated (this i think we could fix with a templating system. T4 or xslt?)

On the other hand, generating the entire class would help new developers get going faster, perhaps?

Mar 5, 2010 at 12:45 PM

Yeah, the problem with being conventional is that people have their own conventions. Need to give some thought to a templating system.

And as you mentioned, generating just the new stuff is a bit tricky. You could simply have a checkbox "generate everything". If the user doesn't check that, it generates just the test methods, and action methods for whatever has been specified. Then the user just has to copy and paste them in.

Or in the other post I made. If you had a MyFile.story file, some sort of cool, right-click in Visual Studio > StoryQ > Generate missing methods.

I guess ReSharper does take away a lot of the pain. And you could even setup ReSharper templates. It would be awesome to click generate, paste, and just code though.

 

Coordinator
Mar 5, 2010 at 12:49 PM
robertbeal wrote:

 You could simply have a checkbox "generate everything". If the user doesn't check that, it generates just the test methods, and action methods for whatever has been specified. Then the user just has to copy and paste them in.

That's exactly what we used to have. I'll create a work item to add that back in...

As i mentioned in your other post though, visual studio integration is something i'm keen to avoid - i personally feel that the lightweight installation process of storyQ is one of it's differentiating factors.

Mar 5, 2010 at 12:53 PM

True, it's a lightweight lib and easy to add to a project. I'd imagine it's a fair amount of work to write a decent plugin for VS too, effort which could be used elsewhere.

Coordinator
Mar 5, 2010 at 1:22 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.