Giter Club home page Giter Club logo

Comments (6)

untoldwind avatar untoldwind commented on August 24, 2024

I'd say that the interface of the "commands" tests could certainly have some improvements.

The there are two core functions that (unluckily) are not public:

func Prop(commands Commands) gopter.Prop {
return prop.ForAll(func(actions *actions) (*gopter.PropResult, error) {
systemUnderTest := commands.NewSystemUnderTest(actions.initialStateProvider())
defer commands.DestroySystemUnderTest(systemUnderTest)
return actions.run(systemUnderTest)
}, genActions(commands))
}

func (a *actions) run(systemUnderTest SystemUnderTest) (*gopter.PropResult, error) {
state := a.initialStateProvider()
propResult := &gopter.PropResult{Status: gopter.PropTrue}
for _, shrinkableCommand := range a.sequentialCommands {
if !shrinkableCommand.command.PreCondition(state) {
return &gopter.PropResult{Status: gopter.PropFalse}, nil
}
result := shrinkableCommand.command.Run(systemUnderTest)
state = shrinkableCommand.command.NextState(state)
propResult = propResult.And(shrinkableCommand.command.PostCondition(state, result))
}
return propResult, nil
}

Especially the latter should contain everything to create a regression test from a given sequence of commands.
Would it be helpful to make this a public function?
Or maybe all you need is just to make the "action" struct public.

from gopter.

symbiont-sean-lyons avatar symbiont-sean-lyons commented on August 24, 2024

Thanks for the quick response!

I think the actions is pretty close to the process I'm trying to hook into. Although, it would probably be best to just expose a simple method like the following:

func Replay(commands.State,
          commands.SystemUnderTest,
          ...commands.Command) *gopter.PropResult {...}

All that's really necessary is a nice wrapper around the lifecycle of how commands are applied. Think of it like this -- I'm looking for something almost identical to a normal Gopter test, but I want to be able to specify precisely the commands that are generated and I only want to run 1 test case.

from gopter.

untoldwind avatar untoldwind commented on August 24, 2024

Sorry, I was really busy last week and overlooked this.
I created a "devel" branch containing a "command.Replay" function that probably fits your needs (https://github.com/leanovate/gopter/blob/devel/commands/replay.go).
If that is working for you I'll merge it to master

from gopter.

symbiont-sean-lyons avatar symbiont-sean-lyons commented on August 24, 2024

I think what you have there is a working solution, and is very close to what I've been doing myself to solve this problem. I'd be much happier to lean on this feature from the library than my own codebase.

One improvement I could see is a tighter coupling to the workflow run by commands.Prop so that the two cannot diverge in the future. As a consequence of the loose coupling of your current implementation, I don't think shrinking will be applied to regression tests. That's not a major problem, but I'd think it's sub-optimal to not apply shrinking.

I'm also beginning to familiarize myself more with the codebase, and would be happy to start making some contributions of my own on this front soon.

from gopter.

untoldwind avatar untoldwind commented on August 24, 2024

Yes, I see your point.
I did a bit of refactoring. Can you give https://github.com/leanovate/gopter/blob/devel/commands/replay.go
a try.

And yes, for a regression test a shrinker would actually be counter-productive. Its main purpose is trying to find the minimal sequence of commands to fail the system

from gopter.

untoldwind avatar untoldwind commented on August 24, 2024

I merged this version and will close this issue for now.

from gopter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.