lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 2014/7/31 9:57, Coda Highland wrote:
On Wed, Jul 30, 2014 at 6:53 PM, albert_200200 <> wrote:
On 2014/7/31 9:47, Coda Highland wrote:

On Wed, Jul 30, 2014 at 6:44 PM, albert_200200 <>

local M = {}
local function add_internal(a, b)

function M.add(a, b)
     add_internal(a, b)
return M

Is it possible in test.lua to test add_internal of foo.lua?

No. That's sort of the definition of "local".

/s/ Adam

Then the idiom of lunit is that "Don't test the private methods", right?
I don't know if that's necessarily lunit's professed ideal, but it's a
necessary fact of the way Lua is inplemented.

However, it's my opinion that the idiom is true for unit tests in
general -- you're supposed to be testing the interface, not the
implementation. Private methods aren't part of the interface and can
be changed about and refactored, and you don't want to have to change
the tests for the internal parts even though you haven't broken any
user code.

(That said, if you have an inner method that REALLY needs testing, you
could do something like checking for the presence of the test harness
and then export the function publicly. Not the cleanest idea in the
world, but better than not testing.)
Really thanks for your quick reply. Your following meaning I didn't understand well. Do you mean every method I want to make sure it's correct and to test, I should make this method public, Is that your meaning?

/s/ Adam