D
D
demoded2013-01-14 13:53:37
Software testing
demoded, 2013-01-14 13:53:37

Unit testing?

I'm trying to apply testing on my reality and I'm a little skidding.
Here I have a method that receives the record ID in the table and generates XML from it, how it is not clear to me to test it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vsespb, 2013-01-14
@demoded

1) fake db methods that return a record. Verify that the correct XML is generated for this fake data
2) Verify that the method executes a valid database query that returns a record with the given ID.

A
Alexander, 2013-01-14
@akalend

<code>
function testMethod() {
    id = 123;
    data = getMyMethod();
    assertData( data , "<xml><some data="xxx"></xml>" )
}
</code>
1) write a test that calls the method
2) get data
3) compares with the data that should be

I
Ilya Sevostyanov, 2013-01-15
@RUVATA

Canonically unit testing interaction with the database is bad manners :) The database is an entity independent of your code - it provides you with a certain level of guarantees, but nevertheless this is a separate application and it is difficult to talk about covering such a function with tests, such a test is by and large meaningless - t .to. Unexpected database behavior cannot be ruled out.
In this case, as already advised above, you can write an integration test or an application level test, and that’s it, so to speak, for yourself for the development period, later such a test cannot be taken into account in the “coverage”.
Building XML is another matter, here you can and even need a lot of unit testing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question