How to I pass multiple parameters using feature.
I am aware of usage of "Examples:" concept but it's making feature file more complicated and unreadable in some manner
Example:
Scenario Outline: To verify that default value for some timeout when invalid/remove is set for some timeout parameter
When <parameterA> is <action> with <parameterB> for <someOtherParameterPair> in <fileName>
Then <parameterA> is updated with value <parameterB> for <someOtherParameterPair> in <fileName> as per defined <action>
Examples:
|parameterA |parameterB |action|someOtherParameterPair|fileNameWithSectionName|
|oneParameter|twoParameter|update|key:Value |abc.config:appSettings |
|oneParameter|twoParameter|delete|key:Value |def.config:appSettings |
Here, I have around 7 parameters which are coming from testcase(which I have tried to accomodated in 5 parameters due to limitation)
I would be splitting "someOtherParameterPair" and "fileNameWithSectionName" into two using split in step definition file. So in total I have around 7 parameters which will be used in Test Case.
But I am not sure whether accepting such huge number of parameters from Given/When/Then statements are feasible. It's also making my test case unreadable.
In above scenario, I am trying to modify some parameters(which I am passing from feature file so that my When/Then statements could modify) present in *.config file present at certain location.
After which I need to execute the testcase.
In the same manner, I have other(most of them) cases as well in my test suite.
Please help me is BDD right approach. Is BDD going to create some issues in maintenance as I am seeing lots of things (almost everything from) feature file.
The answer is don't write your features like this. Instead of using your feature to describe how you are testing something, use it to explain what you are testing and why you are testing it
Generally this means you don't need to use examples, and you certainly never need to use complicated examples like you've got. You can always push the usage of examples down to a lower level e.g. the step definitions.
In this case it looks like you should be writing a unit test. There is nothing of business value described in this scenario.
BDD is about describing behaviour and using that to drive development. You can't use it to test things after they have been written!!
Related
First of all i'm new here and new to SpecFlow. I'll try to be as clear as possible because I'm still exploring ways to solve my problems so please bear with me :)
Alright here I go. I have a solution (lets call it DBHelper) that does a few operations on a Database and i want to provide a tool in BBD (using specflow) to determine and set up a test suite using test rail that will run automatically. These tests could be a set composed of single scenario run several times but with different values. I'm still very early in the development of this tool so the version i have right now is connected to DBHelper and does a single operation when i run either SpecRun of NUnit.
Here is my scenario:
Scenario: InsertBuildCommand
Given The build name is AmazingTest
And The build type is Test
And The platform is PC
And The number of files in the build is 13
And Each file is 8 MB
And The project code name is UPS
And The studio code name is MTL
And The environment is TEST
When The command executes
Then The build should be inserted in the DB with the correct files in it
Now i am looking fo a way to make the scenario dynamic. I ultimatelly want the user to enter be able to run the scenario but his choice of values (ex: the name of the build would be MoreAmazingTest) without being in VS. I know you can run SpecRun from the command line but i am clueless as to how to close the gap between the orignally hardcoded scenario values and the user input. The steps contain regular expression where it is useful so it really is just about the scenario values.
Someone told me about coding a custom plugin or reverse engineer Specrun and make a modified version of it but i have no idea how that would help me. Pardon me if it all makes sense i'm not en expert :x
Thanks alot!
If I understand your question properly, you can use Scenario Outline rather than Scenario. Scenario Outline help
You would then have something like this:
Scenario Outline: test using multiple examples
Given I do something
When I enter <numbers>
And I click a button
Then I will have an answer
Examples:
|numbers|
|1 |
|2 |
|3 |
It will then run the same scenario for each example given.
One way is to define some kind of configuration file which the step definitions will read and perform the tests on it. After you change the file you can run the tests however you want, from a command line or VS and it will read the file and get the numbers from there.
I use environment variables for that.
But if you really need arguments, you could also create an .exe (consoleapp) which uses specflow/nunit/etc to pass the cmd arguments to your classes.
I apologize in advance for the generic nature of my question, but I was unable to find any helpful advice from people trying to do the same thing as me on the web. Let me describe my scenario:
I am providing end users/designers of a website the ability to customize their views by storing the views (using Razor) in the database. I have all of this working, but my question is the following; From a security standpoint, how can I ensure and enforce that unwanted code doesn't get executed in the user-defined view? There are two basic approaches that I think will work conceptually, but am not sure which one is more possible or feasible.
Option 1: Create a validation method in the administration tool that allows the user to input the view code. This would need to either take a whitelist or blacklist approach to what is allowable or not.
Option 2: Prevent unwanted code from being able to execute when rendering of the view occurs.
As a quick example of something that would need to be blocked, we wouldn't want to allow access to read or write files, access any data access functions, or even access configuration settings, etc. in the web.config. There will likely be a decently-sized list of things that probably shouldn't be allowable, but I'll need to sit down and try to think of as many security-related concerns as possible.
My question then is, which method would be the best bet? Also, can any direction be provided on how to go about either? I thought I might be able to make trust-level based change which would be Option 2, but couldn't find any way to make that work in a per-view based manor (the administration code is allowed to execute whatever it wants). I'm thinking Option 1 will end up being the best bet and I'll have to check for the input of certain framework functions that shouldn't be allowed. Does anyone have any experience doing anything like what I'm trying to do? ANY feedback is much appreciated!
This would be extremely difficult.
You could run the the template through the Razor preprocessor, then use Roslyn (still in early beta) to parse the generated file and look through all method calls (or constructors) and return an error if it calls something you don't like.
I strongly recommend that you use a whitelist for that, since the .Net framework is big enough that you are bound to overlook something in a blacklist.
However, I would instead recommend that you not use Razor at all and instead use a templating engine that does not allow real C# code.
On high level my problem is -
We have couple of applications which have millions of lines of legacy code (C# and SQL). I need to figure out code areas which are being used most?
It may not be possible to find exact figures (especially in apps when code is being called based on user's action in GUI).
However, to get some rough figures few thoughts I have are to find out:
1) Find out List of Classes and Methods
2) Find out number of time they are called from within the code. (by means of direct method calls/delegates etc)
3) Find out all the stored procs/db functions (this would be bit staright forward)
4) Find out all the calls to stored procs
Could you please let me know - if you are aware of any tools to achive this?
Or any other idea to fetch above 4 details? Also, apart from these any other way to to do this analysis?
Thanks in advance!
I have used Red Gate's ANTS Profiler before:
http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/
It's powerful and very easy to use (comes with a visual studio plugin). 14 days free!
One way you could achieve this is using Aspect Oriented Programming (AOP). I have used this previously in Java with the Spring Framework, but haven't used it before on .NET projects.
You could check out something like;
http://blogs.msdn.com/b/morgan/archive/2008/12/18/method-entry-exit-logging.aspx
This will give you an idea of how frequently methods are being called. Your will need simply need to collate the data in the logs into some form giving you an overall idea of usage patterns of the codebase.
Edit:
Further information on using this method can be found on other SO posts;
Logging entry and exit of methods along with parameters automagically?
https://stackoverflow.com/a/25825/685760
I have the situation that the same repeating refactoring tasks have to be done for a huge number of methods in my code.
For example imagine a interface with 100 methods, each of them has one or more parameters as well as a return value. For each of these methods I need to jump to the implementation change the return type and add a line of code which converts the old return value to its new type for callers of the interface method.
Is there any way to quickly automate such refactorings?
I even thought to write a custom script to do it, but writing a intelligent script would approximately take longer than doing it maually.
A tool supporting such task can save a lot of time.
It's a good question, but in the time it took since you posted it (not to mention the time you spent searching for an answer before posting), you could have completed the changes manually.
I know, I know, it's utterly unsatisfying, but if you think of it as a form of mediation, and only do this once a year, it's not that bad.
If your problem is one interface with 100 methods, then I agree with another poster: just doing it may seem painful but it is limited in effort and you can be done really soon.
If you have this problem repeatedly, or you have very large code base (many, many interfaces for which you want to perform this task), then what you need is a tool for implementing automated change: a program transformation engine. Such a tool provides the ability to parse source code, build a program representation (an abstract syntax tree), and enables one to apply "scripted" operations on the tree either through procedural interfaces and/or through source-to-source transformation patterns.
OUr DMS Software Reengineering Toolkit is such a program transformation system. It has a C# Front End to enable its application to C# code. Configuring such a tool for a complex task is not a matter of hours, so it is not useful for "small scale" changes. For large scale changes, such tools can make it possible to do things simply not practical by hand.
Resharper and CodeRush both have features which can help with this kind of task.
Resharper's change signature functionality is probably the closest match.
Can't you generate a new interface from the class you have and then remove the ones you don't need! if it's that simple!!
change the return type : by changing... the return type, provided it is not a standard type (...), and the converter can be implemented by a TypeConverter.
When i have such boring task to do, i often switch VS2010 and use a tool that allow regex search and replace. In your example, maybe change 'return xxx;' by 'var yyy=convert(xxx); return yyy;'
(for example editor Notepad++ (free) allready offers quite some possiblities to change everything in a project (use with caution))
I have one class which talks to DataBase.
I have my integration-tests which talks to Db and asserts relevant changes. But I want those tests to be ignored when I commit my code because I do not want them to be called automatically later on.
(Just for development time I use them for now)
When I put [Ignore] attribute they are not called but code-coverage reduces dramatically.
Is there a way to keep those tests but not have them run automatically
on the build machine in a way that the fact that they are ignored does
not influence code-coverage percentage?
Whatever code coverage tool you use most likely has some kind of CoverageIgnoreAttribute or something along those lines (at least the ones I've used do) so you just place that on the method block that gets called from those unit tests and you should be fine.
What you request seems not to make sense. Code-Coverage is measured by executing your tests and log which statements/conditions etc. are executed. If you disable your tests, nothing get executed and your code-coverage goes down.
TestNG has groups so you can specify to only run some groups, automatically and have the others for usage outside of that. You didn't specify your unit testing framework but it might have something similar.
I do not know if this is applicable to your situation. But spontaneously I am thinking of a setup where you have two solution files (.sln), one with unit/integration tests and one without. The two solutions share the same code and project files with the exception that your development/testing solution includes your unit tests (which are built and run at compile time), and the other solution doesn't. Both solutions should be under source control but only the one without unit tests are built by the build server.
This kind of setup should not need you to change existing code (too much). Which I would prefer over rewriting code to fit your test setup.