I created an Ordered Test in Visual Studio 2008, which includes a subset of unit tests in the project.
How do I now run this Ordered Test (without running every other test).
I could not confirm whether to do these tests. It seems the set and get method is so simple,such as:
setA(String A) {
this.A = A;
}
getA(){
return A;
}
Any ideas would be appreciated!
Thanks,
Joseph
Hi, I have heard that MbUnit comes with pretty nice test decorators which allow writing db-related tests with ease.
I am struggling to find good documentation with samples.
Also, can the same thing be achieved with the latest Micosoft's Test package?
Many thanks.
I recently obtained a Mac so I could test our sites on Safari and Firefox for Mac OS.
Now that Safari 5 is out, I'm not sure what I should do about upgrading. I presume what works on Safari 5 works on Safari 4, but I can't be sure, and vice versa. So, I don't know if I should upgrade and test on Safari 5 or keep on with Safari 4.
Are there any major differences between these two version in terms of CSS (2.1) handling or JavaScript? When do you think the majority of people will have Safari 5 instead of 4?
All thoughts appreciated.
Hello,
I have the following test method (VB.NET)
<RowTest()> _
<Row(1, 2, 3)> _
Public Sub AddMultipleNumbers(ByVal number1 As Integer, ByVal number2 As Integer, ByVal result As Integer)
Dim dvbc As VbClass = New VbClass()
Dim actual As Integer = dvbc.Add(number1, number2)
Assert.That(actual, [Is].SameAs(result))
End Sub
My problem is that when the test runs, using TestDriven.Net, the three method parameters are 0 and not the values I am expecting. I have referenced the NUnit.Framework (v.2.5.3.9345) anf the NUnitExtension.RowTest (v.1.2.3.0).
We have splitted our grails application into several inplace-plugins.
Now we want to have the tests in the same plugin like the classes which they test.
Is it possible to configure our application (e.g. in BuildConfig.groovy) so that the tests in the plugins are executed too when we run "test-app"?
Is it possible to perform unittest tests via a web interface...and if so how?
EDIT:
For now I want the results...for the tests I want them to be automated...possibly every time I make a change to the code. Sorry I forgot to make this more clear
Here is the mysterious:
I have a scope which looks like this (in Image.rb)
scope :moderate_all, delegates.where("moderation_flag = #{$moderation_flags[:not_moderated]}")
Note that delegates is another scope that I am defining before moderate_all
When I leave it like this, I can run my test that checks if an image has been "checked-out" it is not available anymore. I don't put the code of the test, because it does not matter actually.
With this code, when I run "rake test" it fails, but if I do "ruby test/unit/image_test.rb" it works! I was thinking I am starting to have a bad day. Then I tried
scope :moderate_all, lambda {
delegates.where("moderation_flag = #{$moderation_flags[:not_moderated]}")
}
And "rake test" passes!
So my problem is solved, but why?
Hi folks,
I'm trying to mock up a fake ASP.NET Controller. I don't have any concrete controllers, so I was hoping to just mock a Controller and it will work.
This is what I have, currently.
_fakeRequestBase = MockRepository.GenerateMock<HttpRequestBase>();
_fakeRequestBase.Stub(x => x.HttpMethod).Return("GET");
_fakeContextBase = MockRepository.GenerateMock<HttpContextBase>();
_fakeContextBase.Stub(x => x.Request).Return(_fakeRequestBase);
var controllerContext = new ControllerContext(_fakeContextBase, new RouteData(),
MockRepository.GenerateMock<ControllerBase>());
_fakeController = MockRepository.GenerateMock<Controller>();
_fakeController.Stub(x => x.ControllerContext).Return(controllerContext);
Everything works except the last line, which throws a runtime error and is asking me for some Rhino.Mocks source code or something (which I don't have).
See how I'm trying to mock up an abstract Controller - is that allowed?
Can someone help me?
Hi,
this is something I know I should embrass in my coding projects but, due to lack of knowledge and my legendary lazyness, I do not do.
In fact, when I do them, I feel like overloaded and I finally give up.
What I am looking for is a good book/tutorial on how to really write good tests -i.e useful and covering a large spectrum of the code -.
Regards
for metrics reasons I need to know how many lines of code my class library has. I'm doing this for code coverage....
So if Class library 1 has 50 lines of code and 100% coverage
And if Class library 2 has 500 lines of code and 0% coverage
My total coverage is 90%
Any idea how to do this? Is there a utility or a way to use Visual Studio?
I'm trying to modify my test projuect to allow for remote invocation of an api we're building. Right now the tests are hard coded to run locally(against localhost), but I would like to be able to point the tests at any endpoint (even remote ones in production).
Ideally there would be a place in the .testsettings for config values to be stored. Sadly this isn't the case.
Or, being able to pass parameters to MSTest that the test would read...?
Any ideas? Thanks in advance.
Hi,
I was wondering if there was anything that provides test data for injecting into Nunit tests?
I'm sure I came across something recently that does this but I couldn't find it again.
Basically the idea is that I could use selenium and Nunit to create new customers within the system automatically.
So I could have selenium type in customer names generated from test generator (the < DataGenerator is just an imaginary class):
e.g.
dim sFirstName as string = < DataGenerator >.GetRandomFirstName()
dim sLastName as string = < DataGenerator >.GetRandomLastName()
selenium.type("firstname_field",sFirstName)
selenium.type("lastname_field",sLastName )
I've already seen SQLDataGenerator from Redgate which has a cmd line wrapper class, but I was wondering if there was anything else.
How do you know if you "Test Fixture" is right-sized. And by "Test Fixture" I mean a class with a bunch of tests in it.
One thing that I've always noticed with my test fixtures is that they get to be kind of verbose; seeing as they could also be not verbose enough, how do you get a sense of when your unit tests are the right size?
My assumption is that (at least in the context of web development) you should have one test fixture class per page.
I know of a good quote for this and it's:
"Perfection is achieved, not when there is nothing left to add, but when there is nothing left to remove." - Antoine de Saint-Exupery.
I am supposed to be using test-driven development but in this particular case, as I am having trouble, I implemented the action method first. It looks like this:
public ViewResult Index(int pageNumber = 1)
{
var posts = repository.All();
var model = new PagedList<Post>(posts, pageNumber, PageSize);
return View(model);
}
Both the repository and the PagedList<> have been tested already. Now I want to verify that when the action is given a page number that the page number is actually considered.
private Mock<IPostsRepository> repository;
private HomeController controller;
[Test]
public void Index_Doohickey()
{
var actual = controller.Index(2);
// .. How do I test that the controller actually uses the page number here?
}
I am quite new to TDD and am going with NUnit and Moq. I have got a method where I expect an exception, so I wanted to play a little with the frameworks features.
My test code looks as follows:
[Test]
[ExpectedException(ExpectedException = typeof(MockException), ExpectedMessage = "Actual differs from expected")]
public void Write_MessageLogWithCategoryInfoFail()
{
string message = "Info Test Message";
Write_MessageLogWithCategory(message, "Info");
_LogTest.Verify(writeMessage =>
writeMessage.Info("This should fail"),
"Actual differs from expected"
);
}
But I always receive the errormessage that the error message that the actual exception message differs from the expected message. What am I doing wrong?
Is it better to write/record selenium tests in html format and run them directly in the server with "-htmlSuite" or to write the tests in java/C#/... and run them in the server using selenium-rc?
What is the recommended solution?
Is there any good framework for comparing whole objects?
now i do
assertEquals("[email protected]", obj.email);
assertEquals("5", obj.shop);
if bad email is returned i never get to know if it had the right shop, i would like to get a list of incorrect fields.
We have a number of integration tests that fail when our staging server goes down for weekly maintenance. When the staging server is down we send a specific response that I could detect in my integration tests. When I get this response instead of failing the tests I'm wondering if it is possible to skip/ignore that test even though it has started running. This would keep our test reports a bit cleaner.
Does anybody have suggestions?
Basically I have a tear down method that I want to log to the console which test was just run. How would I go about getting that string?
I can get the class name, but I want the actual method that was just executed.
Class testSomething() {
@AfterMethod
public void tearDown() {
system.out.println('The test that just ran was....' + getTestThatJustRanMethodName()');
}
@Test
public void testCase() {
assertTrue(1==1);
}
}
should output to the screen: "The test that just ran was.... testCase"
However I don't know the magic that getTestThatJustRanMethodName should actually be.
UPDATE: I've changed the wording of the question. Previously it was a yes/no question about if a base class could be changed at runtime.
I may be working on mission impossible here, but I seem to be getting close. I want to extend a ASP.NET control, and I want my code to be unit testable. Also, I'd like to be able to fake behaviors of a real Label (namely things like ID generation, etc), which a real Label can't do in an nUnit host.
Here a working example that makes assertions on something that depends on a real base class and something that doesn't-- in a more realistic unit test, the test would depend on both --i.e. an ID existing and some custom behavior.
Anyhow the code says it better than I can:
public class LabelWrapper : Label //Runtime
//public class LabelWrapper : FakeLabel //Unit Test time
{
private readonly LabelLogic logic= new LabelLogic();
public override string Text
{
get
{
return logic.ProcessGetText(base.Text);
}
set
{
base.Text=logic.ProcessSetText(value);
}
}
}
//Ugh, now I have to test FakeLabelWrapper
public class FakeLabelWrapper : FakeLabel //Unit Test time
{
private readonly LabelLogic logic= new LabelLogic();
public override string Text
{
get
{
return logic.ProcessGetText(base.Text);
}
set
{
base.Text=logic.ProcessSetText(value);
}
}
}
[TestFixture]
public class UnitTest
{
[Test]
public void Test()
{
//Wish this was LabelWrapper label = new LabelWrapper(new FakeBase())
LabelWrapper label = new LabelWrapper();
//FakeLabelWrapper label = new FakeLabelWrapper();
label.Text = "ToUpper";
Assert.AreEqual("TOUPPER",label.Text);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
label.RenderControl(writer);
Assert.AreEqual(1,label.ID);
Assert.AreEqual("<span>TOUPPER</span>", stringWriter.ToString());
}
}
public class FakeLabel
{
virtual public string Text { get; set; }
public void RenderControl(TextWriter writer)
{
writer.Write("<span>" + Text + "</span>");
}
}
//System Under Test
internal class LabelLogic
{
internal string ProcessGetText(string value)
{
return value.ToUpper();
}
internal string ProcessSetText(string value)
{
return value.ToUpper();
}
}
This is also a question that I asked in a comment in one of Miško Hevery's google talks that was dealing with dependency injection but it got buried in the comments.
I wonder how can the factory / builder step of wiring the dependencies together can work in C++.
I.e. we have a class A that depends on B. The builder will allocate B in the heap, pass a pointer to B in A's constructor while also allocating in the heap and return a pointer to A.
Who cleans up afterwards? Is it good to let the builder clean up after it's done? It seems to be the correct method since in the talk it says that the builder should setup objects that are expected to have the same lifetime or at least the dependencies have longer lifetime (I also have a question on that). What I mean in code:
class builder {
public:
builder() :
m_ClassA(NULL),m_ClassB(NULL) {
}
~builder() {
if (m_ClassB) {
delete m_ClassB;
}
if (m_ClassA) {
delete m_ClassA;
}
}
ClassA *build() {
m_ClassB = new class B;
m_ClassA = new class A(m_ClassB);
return m_ClassA;
}
};
Now if there is a dependency that is expected to last longer than the lifetime of the object we are injecting it into (say ClassC is that dependency) I understand that we should change the build method to something like:
ClassA *builder::build(ClassC *classC) {
m_ClassB = new class B;
m_ClassA = new class A(m_ClassB, classC);
return m_ClassA;
}
What is your preferred approach?
I need to automate the build/deploy process for my iphone applications from a script. I can use xcodebuild to build the project, then use Applescript to deploy and debug/run the application. Assuming the application will stop by itself after a while, I need to collect the generated logs for verification. But the problem is I have no way to know when the application ended from outside of the application itself. If the running time is fixed, I can again use Applescript to stop the application (Cmd+Shift+Enter). So there has to be a way to connect to the device/simulator and wait on the application somehow.
Seems unlikely, but is there any way to generate a set of unit tests for the following rewrite rule:
RewriteRule ^/(user|group|country)/([a-z]+)/(photos|videos)$ http:/whatever?type=$1&entity=$2&resource=$3
From this I'd like to generate a set of urls of the form:
/user/foo/photos
/user/bar/photos
/group/baz/videos
/country/bar/photos
etc...
The reason I don't want to just do this once by hand is that I'd like the bounded alternation groups (e.g. (user|group|country)) to be able to grow and maintain coverage without having the update the tests by hand.
Is there a rewrite rule or regex parser that might be able to do this, or am I doing it by hand?