Unit tests in Leo

T

Tomi Lindberg

I'm quite (or very) new to both unit testing and Leo. I've
been trying to get @test nodes to work without success so
I'd like to have very simple example.

So, if I have a @file with the following content...

def divide_by_two(x):
return x/2

....and I'd like to write a @test node that checks whether
the function returns the right number ( like
assertsEqual(divide_by_two(8), 4) ). Now, what should the
@test node look like?
 
A

ajikoe

Hello Tomi,

I'm not really sure about your question, but concerning unit testing
you can do a simple test.

import unittest

First: in your module (where you define functions) you should create a
class which use unittest.TestCase as your superclass.

Second: Use method runTest to type your test

Third: below the __name__ == "__main__" type unittest.main();

For example:
class testMyFunc(unittest.TestCase):
def runTest(self):
h = myFunc()
self.assertEqual(something,h)
#----------------------
if __name__ == "__main__":
unittest.main();


Sincerely Yours,
Pujo
 
T

Tomi Lindberg

Hello Tomi,

I'm not really sure about your question, but concerning unit testing
you can do a simple test.

No problem. I found the Leo forums at Source Forge and I've
already received some answers in there. Thanks for replying
though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,809
Latest member
Adisty

Latest Threads

Top