lundi 2 février 2015

GoogleMock: Expect either of two method calls

I have a class Foo that references multiple other objects of type IBar. The class has a method fun that needs to invoke method frob on at least one of those IBars. I want to write a test with mocked IBars that verifies this requirement. I'm using GoogleMock. I currently have this:



class IBar { public: virtual void frob() = 0; };
class MockBar : public IBar { public: MOCK_METHOD0(frob, void ()); };

class Foo {
std::shared_ptr<IBar> bar1, bar2;
public:
Foo(std::shared_ptr<IBar> bar1, std::shared_ptr<IBar> bar2)
: bar1(std::move(bar1)), bar2(std::move(bar2))
{}
void fun() {
assert(condition1 || condition2);
if (condition1) bar1->frob();
if (condition2) bar2->frob();
}
}

TEST(FooTest, callsAtLeastOneFrob) {
auto bar1 = std::make_shared<MockBar>();
auto bar2 = std::make_shared<MockBar>();
Foo foo(bar1, bar2);

EXPECT_CALL(*bar1, frob()).Times(AtMost(1));
EXPECT_CALL(*bar2, frob()).Times(AtMost(1));

foo.fun();
}


However, this doesn't verify that either bar1->frob() or bar2->frob() is called, only that neither is called more than once.


Is there a way in GoogleMock to test for a minimum number of calls on a group of expectations, like a Times() function I can call on an ExpectationSet?


How can I call CXF Endpoint manually with String as SOAP Message

I would like to make a test of the webservice without putting it into server. I have my Endpoint from spring:



<jaxws:endpoint id="authorizationServiceEndpoint_v1" implementor="#AuthorizationService_v1" address="/AuthorizationService_v1">


and I have prepared my test message



<soapenv:Envelope bla bla >


How can I pass my message to the Enpoint and make it execute (and get result)?


Please avoid comments like "it's not the way you should test it" :)


Slow Test Explorer

I work with TFS and MS test framework using Visual Studio 2012. I have 200 unit tests under Test Explorer. Each time, I recompile my code; the tests reload extremely slowly. Each test has an attribute of TestCategory which is defined by a given constant.


Is there any solution to make the test reload faster?


How to write test cases for Jmeter for SOAP request

I want to write test cases for 500 concurrent user with 500 concurrent queries. How to write the above test cases for Jmeter for SOAP request.


dimanche 1 février 2015

Why is my branch coverage rate and line coverage rate failing?

Consider the following code:



@Test
public final void testIsUnitInvalidSadCase() {
boolean expectedResult = false;
boolean actualResult = false;
double invalidUnit = 0.0;

testFuelUnitValidator =
new FuelUnitValidator(
defaultTimestamp,
defaultFluids,
invalidUnit);

actualResult = testFuelUnitValidator.isUnitInvalid();

assertThat(actualResult, is(equalTo(expectedResult)));
}

@Test
public final void testIsUnitInvalidHappyCase() {
boolean expectedResult = false;
boolean actualResult = true;
double invalidUnit = 0.02;

testFuelUnitValidator =
new FuelUnitValidator(
defaultTimestamp,
defaultFluids,
invalidUnit);

actualResult = testFuelUnitValidator.isUnitInvalid();

assertThat(actualResult, is(equalTo(expectedResult)));
}


This is the method:



public boolean isUnitInvalid() {
if (Math.abs(unit) < 0.0) {
return true;
}
return false;
}


When I change the line as if (Math.abs(smu) <= 0.01) and the test classes as boolean expectedResult = true; for the first test then the maven builds up fine. But when I try to build with above code, maven throws an error as: [ERROR] *className failed check. Branch coverage rate of 95.8% is below 100.0% *className failed check. Line coverage rate of 97.8% is below 100.0%


Click a Dropdowm Menu Button using Watin

I am testing a website using Watin in the page there is dropdown menu button like [Download|V] if I find that button and click it clicks the entire button and selects the first Option in the menu but I want to click the V of the button to show the dropdown menu(div) and select the option from it the code I had tried to click the button



ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent("onmouseover");
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent(" Onmousedown");
ff.Div(Find.ById("x-auto-457")).Click();


the Button HTML



<button class="x-btn-text" style="position: relative; width: 16px;" type="button" tabindex="0" aria-describedby="x-auto-456">

Grails integration test not recognising controller save method

I recently upgraded a project from 2.2 to 2.4.4, and upgraded the integration tests by replacing



IntegrationTest extends GroovyTestCase


with



@TestMixin(IntegrationTestMixin)


My controllers have save methods e.g. :



class IssueController {

def save() {
...
if (!issueService.save(issue)) {
render(view: "create", model: [issueInstance: issue])
return
}
}


and the integration test (in test/integration) :



@Before
void setUp() {
ic = new IssueController()
}

@Test
void testValidSave() {

ic.params.issueNo = "test"

ic.save()
assert ic.flash.successAlert == "Saved issue test"
assert ic.response.redirectUrl == '/issue/list'
}


but my Integrations tests, when calling ic.save() don't call the controller save method (and so fail). If I rename the save() method to say saveIt(), and the call to ic.saveIt(), everything works fine


but I don't want to have to rename all my controller method names.