unit-testing

When to use a unit testing framework (vs. just using asserts)?

孤街醉人 提交于 2021-02-07 12:09:28
问题 Using a small (currently at 150 loc, probably less than 500 when finished) C project I'm working on, I'm teaching myself test driven development. Based on some stuff I've found on the web - especially these slides by Olve Maudal, I've just been using asserts in my unit tests. Since I'm just learning tdd, I have thus far avoided the overhead of also learning a unit testing framework such as cunit. At this point, my thinking is that the additional learning curve - even if shallow - of a

Why does my HUnit test suite fail but pass successfully in Cabal?

荒凉一梦 提交于 2021-02-07 11:54:21
问题 If I have test/Test.hs with module Main where import Test.HUnit test1 :: Test test1 = TestCase $ assertEqual "Should be one" 1 5 test2 :: Test test2 = TestCase $ assertEqual "Shold both be zero" 0 0 main :: IO Counts main = runTestTT $ TestList [test1, test2, test1] and a .cabal with test-suite my-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Test.hs build-depends: base >= 4.8.1.0 && <4.9, HUnit >= 1.3 default-language: Haskell2010 and I run cabal test --show-details='always'

Why does my HUnit test suite fail but pass successfully in Cabal?

拟墨画扇 提交于 2021-02-07 11:54:06
问题 If I have test/Test.hs with module Main where import Test.HUnit test1 :: Test test1 = TestCase $ assertEqual "Should be one" 1 5 test2 :: Test test2 = TestCase $ assertEqual "Shold both be zero" 0 0 main :: IO Counts main = runTestTT $ TestList [test1, test2, test1] and a .cabal with test-suite my-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Test.hs build-depends: base >= 4.8.1.0 && <4.9, HUnit >= 1.3 default-language: Haskell2010 and I run cabal test --show-details='always'

Using Rewire with TypeScript

。_饼干妹妹 提交于 2021-02-07 11:49:20
问题 I am working on a React-Native project using TypeScript. To write my unit tests I would like to use the babel-plugin-rewire to mock my module imports. However, TypeScript adds a _1 suffix at the end of imports while converting from ES6 to ES5, and this breaks my test code. Consider the following: import Test from 'test-file'; this might be converted by TypeScript to: var test_file_1 = require('test-file'); To mock the Test class using the Rewire plugin I would have to write: ComponentToTest._

Is componentDidMount supposed to run with shallow rendering in Enzyme?

前提是你 提交于 2021-02-07 11:17:47
问题 From my understanding and from what I have read so far in various answers, not all lifecycle methods are supposed to be run with shallow rendering. Especially componentDidMount However, I notice that when I do beforeEach(function () { fakeComponentDidMount = sinon.stub(Component.prototype, 'componentDidMount'); fakeComponentDidMount.callsFake(function () {}); wrapper = shallow(<Component {...props} />); }); afterEach(function () { fakeComponentDidMount.restore(); }); it('calls

How to test the main package in Golang from a “test” package?

南楼画角 提交于 2021-02-07 10:26:36
问题 I have a simple program written in Golang. It's an API. So inside the project folder, there's a folder named cmd containing my main package (used to initialise the app and defines the endpoints for the API). There's also a folder named after my program, containing multiple files from a package also named after my program. This package serves as the model to do all the necessary queries and contains all the types I have defined. I also created a folder called test . It contains all my test

How to test the main package in Golang from a “test” package?

旧时模样 提交于 2021-02-07 10:25:21
问题 I have a simple program written in Golang. It's an API. So inside the project folder, there's a folder named cmd containing my main package (used to initialise the app and defines the endpoints for the API). There's also a folder named after my program, containing multiple files from a package also named after my program. This package serves as the model to do all the necessary queries and contains all the types I have defined. I also created a folder called test . It contains all my test

Pass argument or option to Unit Tests from VSTest.Console.exe

邮差的信 提交于 2021-02-07 08:28:01
问题 I can successfully run the VS unit tests from the command line (and hence from the build on the build machine). VSTest.Console.EXE "MyTest.dll" /logger:trx /platform:x64 /inIsolation I can also filter out any required tests that I don't want to execute on a certain environment with /TestCaseFilter option: VSTest.Console.EXE "MyTest.dll" /TestCaseFilter:Name!=Verify_DigitallySigned This is needed to not to run "check if digitally signed" test(s). This way I can filter out the required set of

Pass argument or option to Unit Tests from VSTest.Console.exe

て烟熏妆下的殇ゞ 提交于 2021-02-07 08:27:49
问题 I can successfully run the VS unit tests from the command line (and hence from the build on the build machine). VSTest.Console.EXE "MyTest.dll" /logger:trx /platform:x64 /inIsolation I can also filter out any required tests that I don't want to execute on a certain environment with /TestCaseFilter option: VSTest.Console.EXE "MyTest.dll" /TestCaseFilter:Name!=Verify_DigitallySigned This is needed to not to run "check if digitally signed" test(s). This way I can filter out the required set of

Simplify Django test set up with mock objects

谁说我不能喝 提交于 2021-02-07 08:20:34
问题 Often when I'm writing tests for my Django project, I have to write a lot more code to set up database records than I do to actually test the object under test. Currently, I try to use test fixtures to store the related fields, but could I use mock objects to mock out the related tables that take so much work to set up? Here's a trivial example. I want to test that a Person object will spawn() children according to its health. In this case, a person's city is a required field, so I have to