Just wanting feedback into a crazy idea I had. I'm not sure if anyone has already done something similiar, or even if it's a bad idea. That's why I would like feedback...
Scenario:
In an Umbraco installation we commonly have various nodes used for storing "extra" information. These may be for configuration, tags, categories, carousel items, relations, nodes which contain lists, etc.
To get values from these nodes, we may need to write some code to crawl up the tree, find some container node which is a child of the root, make sure the node exists, get a property, then default to some other value of the property is empty.
Add to the mix, hierarchical configurations where you default to values which are stored in nodes up the tree.
How do you unit test the code which crawls the tree?
Also, what about if you want to create, delete, update nodes using the API? How do you unit test these?
It's quite easy to write code to test if a node exists, or if a value exists, or is a value that is expected. The problem is the HttpContext. You cant automate the code that you wrote to do the test.
But you can wire that up to a button click right?
So here's the plan (open to comments)...
Writing the tests...
Write the test code using NUnit or whatever.
Run the tests on click of a button
Output the test results to a .net label.
In a Team City step, run Selenium to do the click. If the word "error" appears, the testing failed.
But what about unit test data? Don't we want to set up some data (ie Umbraco nodes)?
Setting up your database and test data
In Team City, run a config transform to point Umbraco to a test database. Ideally in a test environment, but can do on your dev server if you want.
In a Team City, run a step (using raw sql or Redgate SQL Compare etc) to restore a clean backup of your project's db. This db should have all the doctypes and some basic tree structure you want to do your testing on.
In your unit test's setup (NUnit or whatever), write some code to create what ever scenarios/node structures etc that you need to test.
There's automated tests of getting/creating/deleting/updating nodes and values in a nutshell.
Unit testing even with HttpContext
Just wanting feedback into a crazy idea I had. I'm not sure if anyone has already done something similiar, or even if it's a bad idea. That's why I would like feedback...
Scenario:
In an Umbraco installation we commonly have various nodes used for storing "extra" information. These may be for configuration, tags, categories, carousel items, relations, nodes which contain lists, etc.
To get values from these nodes, we may need to write some code to crawl up the tree, find some container node which is a child of the root, make sure the node exists, get a property, then default to some other value of the property is empty.
Add to the mix, hierarchical configurations where you default to values which are stored in nodes up the tree.
How do you unit test the code which crawls the tree?
Also, what about if you want to create, delete, update nodes using the API? How do you unit test these?
It's quite easy to write code to test if a node exists, or if a value exists, or is a value that is expected. The problem is the HttpContext. You cant automate the code that you wrote to do the test.
But you can wire that up to a button click right?
So here's the plan (open to comments)...
Writing the tests...
But what about unit test data? Don't we want to set up some data (ie Umbraco nodes)?
Setting up your database and test data
There's automated tests of getting/creating/deleting/updating nodes and values in a nutshell.
Comments?
For the Unit test pureists...
Yes the terminology is not correct.
The point is to automate testing of "units" of our code. But I guess the dependency of Umbraco as a data layer makes this an integration test.
We want to test things like tree traversal. Eg. there should only be ONE or none:
return node.GetChildrenAsList.Items.SingleOrDefault(x => x.NodeTypeAlias == "asdf")
We also want to test return values based on existence of specific nodes. eg:
if (node.Parent != null && node.Parent.NodeTypeAlias == "asdfasdf")
return node.Parent.Name + "-" + node.Name;
else
return node.Name;
is working on a reply...