IDEAS home Printed from https://ideas.repec.org/a/eee/ecomod/v520y2026ics0304380026001973.html

Testing NetLogo model code

Author

Listed:
  • Railsback, Steven F.
  • Bliven, Jocelyn
  • Grimm, Volker
  • Kelter, Jacob

Abstract

In simulation modeling, good code testing practices provide (a) efficiency, by reducing time wasted using erroneous software; (b) credibility, by providing evidence that important errors are unlikely; and (c) understanding, by showing how complex model results arose. However, code testing receives little attention in agent-based modeling, and many modeling projects have been derailed by undetected code errors. We present code testing methods appropriate for models implemented in NetLogo by novice programmers. An efficient cycle for implementing new models includes: drafting a written model description and testing the “submodels” that each represent a separate process, coding the model while updating the written description to correct ambiguities and errors, and then thorough code testing. As the model is then used and revised, the written description, code, and code tests are all updated. We identify eight kinds of errors that are especially common in NetLogo software. Logic errors are the hardest to detect; doing so typically requires producing detailed test output for key submodels and then analyzing that output for unexpected results. We provide methods for producing test output, with example NetLogo code. Test output can be analyzed graphically, statistically, by tracing the fate of individual agents, or by comparing it to an independent implementation of the submodel. When unexpected results are found, a variety of “debugging” methods help determine whether they are caused by software errors and, if so, where the errors are. Documenting code testing methods and results is also key to model credibility and efficiency: documented tests provide evidence that the code is reasonably error-free and makes it easier to repeat tests as models are revised. While NetLogo currently lacks code-testing tools such as stepwise debuggers and unit testers, its powerful commands make it easy to add similar capabilities to models.

Suggested Citation

  • Railsback, Steven F. & Bliven, Jocelyn & Grimm, Volker & Kelter, Jacob, 2026. "Testing NetLogo model code," Ecological Modelling, Elsevier, vol. 520(C).
  • Handle: RePEc:eee:ecomod:v:520:y:2026:i:c:s0304380026001973
    DOI: 10.1016/j.ecolmodel.2026.111669
    as

    Download full text from publisher

    File URL: http://www.sciencedirect.com/science/article/pii/S0304380026001973
    Download Restriction: Full text may be restricted for ScienceDirect subscribers

    File URL: https://libkey.io/10.1016/j.ecolmodel.2026.111669?utm_source=ideas
    LibKey link: if access is restricted and if your library uses this service, LibKey will redirect you to where you can use your library subscription to access this item
    ---><---

    As the access to this document is restricted, you may want to

    for a different version of it.

    References listed on IDEAS

    as
    1. Lemmen, Carsten & Sommer, Philipp Sebastian, 2024. "Good modelling software practices," Ecological Modelling, Elsevier, vol. 498(C).
    2. Volker Grimm & Steven F. Railsback & Christian E. Vincenot & Uta Berger & Cara Gallagher & Donald L. DeAngelis & Bruce Edmonds & Jiaqi Ge & Jarl Giske & Jürgen Groeneveld & Alice S.A. Johnston & Alex, 2020. "The ODD Protocol for Describing Agent-Based and Other Simulation Models: A Second Update to Improve Clarity, Replication, and Structural Realism," Journal of Artificial Societies and Social Simulation, Journal of Artificial Societies and Social Simulation, vol. 23(2), pages 1-7.
    3. Daniel Kornhauser & Uri Wilensky & William Rand, 2009. "Design Guidelines for Agent Based Model Visualization," Journal of Artificial Societies and Social Simulation, Journal of Artificial Societies and Social Simulation, vol. 12(2), pages 1-1.
    4. Ö Gürcan & O Dikenelli & C Bernon, 2013. "A generic testing framework for agent-based simulation models," Journal of Simulation, Taylor & Francis Journals, vol. 7(3), pages 183-201, August.
    5. Swannack, Todd M. & Cushway, Kiara C. & Carrillo, Carra C. & Calvo, Clementina & Determan, Kierra R. & Mierzejewski, Caroline M. & Quintana, Vanessa M. & Riggins, Christopher L. & Sams, Miranda D. & W, 2025. "Cracking the code: Linking good modeling and coding practices for new ecological modelers," Ecological Modelling, Elsevier, vol. 499(C).
    6. Steven F. Railsback & Daniel Ayllón & Uta Berger & Volker Grimm & Steven Lytinen & Colin Sheppard & Jan Thiele, 2017. "Improving Execution Speed of Models Implemented in NetLogo," Journal of Artificial Societies and Social Simulation, Journal of Artificial Societies and Social Simulation, vol. 20(1), pages 1-3.
    Full references (including those not matched with items on IDEAS)

    Most related items

    These are the items that most often cite the same works as this one and are cited by the same works as this one.
    1. An, Li & Grimm, Volker & Sullivan, Abigail & Turner II, B.L. & Malleson, Nicolas & Heppenstall, Alison & Vincenot, Christian & Robinson, Derek & Ye, Xinyue & Liu, Jianguo & Lindkvist, Emilie & Tang, W, 2021. "Challenges, tasks, and opportunities in modeling agent-based complex systems," Ecological Modelling, Elsevier, vol. 457(C).
    2. Meier, Laura & Grimm, Volker & Frank, Karin, 2025. "Model perpetuation by designing and documenting models and workflows so that they can be reused and further developed by others: The case of multiple stressors in ecology," Ecological Modelling, Elsevier, vol. 501(C).
    3. Grimm, Volker & Berger, Uta & Calabrese, Justin M. & Cortés-Avizanda, Ainara & Ferrer, Jordi & Franz, Mathias & Groeneveld, Jürgen & Hartig, Florian & Jakoby, Oliver & Jovani, Roger & Kramer-Schadt, S, 2025. "Using the ODD protocol and NetLogo to replicate agent-based models," Ecological Modelling, Elsevier, vol. 501(C).
    4. Tardy, Olivia & Lenglos, Christophe & Lai, Sandra & Berteaux, Dominique & Leighton, Patrick A., 2023. "Rabies transmission in the Arctic: An agent-based model reveals the effects of broad-scale movement strategies on contact risk between Arctic foxes," Ecological Modelling, Elsevier, vol. 476(C).
    5. Crevier, Lucas Phillip & Salkeld, Joseph H & Marley, Jessa & Parrott, Lael, 2021. "Making the best possible choice: Using agent-based modelling to inform wildlife management in small communities," Ecological Modelling, Elsevier, vol. 446(C).
    6. Dur, Gaël & Won, Eun-Ji & Han, Jeonghoon & Lee, Jae-Seong & Souissi, Sami, 2021. "An individual-based model for evaluating post-exposure effects of UV-B radiation on zooplankton reproduction," Ecological Modelling, Elsevier, vol. 441(C).
    7. Choi, Sunkyung & Maharjan, Rajali & Hong, Tran Thi Nhat & Hanaoka, Shinya, 2024. "Impact of information provision on tsunami evacuation behavior of residents and international tourists in Japan," Transport Policy, Elsevier, vol. 155(C), pages 264-273.
    8. Medeiros-Sousa, Antônio Ralph & Lange, Martin & Mucci, Luis Filipe & Marrelli, Mauro Toledo & Grimm, Volker, 2024. "Modelling the transmission and spread of yellow fever in forest landscapes with different spatial configurations," Ecological Modelling, Elsevier, vol. 489(C).
    9. Anshuka Anshuka & Floris F. Ogtrop & David Sanderson & Simone Z. Leao, 2022. "A systematic review of agent-based model for flood risk management and assessment using the ODD protocol," Natural Hazards: Journal of the International Society for the Prevention and Mitigation of Natural Hazards, Springer;International Society for the Prevention and Mitigation of Natural Hazards, vol. 112(3), pages 2739-2771, July.
    10. Kjær, Lene J. & Schauber, Eric M., 2022. "The effect of landscape, transmission mode and social behavior on disease transmission: Simulating the transmission of chronic wasting disease in white-tailed deer (Odocoileus virginianus) populations using a spatially explicit agent-based model," Ecological Modelling, Elsevier, vol. 472(C).
    11. Butts, David J. & Thompson, Noelle E. & Christensen, Sonja A. & Williams, David M. & Murillo, Michael S., 2022. "Data-driven agent-based model building for animal movement through Exploratory Data Analysis," Ecological Modelling, Elsevier, vol. 470(C).
    12. Sterl, Xenia & Weinans, Els & van der Kaaden, Anna & Doelman, Arjen & Rietkerk, Max, 2026. "A review of dynamics in spatial savanna models," Ecological Modelling, Elsevier, vol. 517(C).
    13. Rahi, Joe El & Weeber, Marc P. & Serafy, Ghada El, 2020. "Modelling the effect of behavior on the distribution of the jellyfish Mauve stinger (Pelagia noctiluca) in the Balearic Sea using an individual-based model," Ecological Modelling, Elsevier, vol. 433(C).
    14. Fouladvand, Javanshir, 2022. "Behavioural attributes towards collective energy security in thermal energy communities: Environmental-friendly behaviour matters," Energy, Elsevier, vol. 261(PB).
    15. Thurner, Stephanie D & Converse, Sarah J & Branch, Trevor A, 2021. "Modeling opportunistic exploitation: increased extinction risk when targeting more than one species," Ecological Modelling, Elsevier, vol. 454(C).
    16. Sandhu, Rimple & Tripp, Charles & Quon, Eliot & Thedin, Regis & Lawson, Michael & Brandes, David & Farmer, Christopher J. & Miller, Tricia A. & Draxl, Caroline & Doubrawa, Paula & Williams, Lindy & Du, 2022. "Stochastic agent-based model for predicting turbine-scale raptor movements during updraft-subsidized directional flights," Ecological Modelling, Elsevier, vol. 466(C).
    17. Van Giel, Thomas & Jaspaert, Hanna & Daly, Aisling J. & De Baets, Bernard & Baetens, Jan M., 2026. "Modification speed and radius of higher-order interactions alter the oscillatory dynamics in an agent-based model," Chaos, Solitons & Fractals, Elsevier, vol. 208(P1).
    18. Crouse, Kristin N. & Desai, Nisarg P. & Cassidy, Kira A. & Stahler, Erin E. & Lehman, Clarence L. & Wilson, Michael L., 2022. "Larger territories reduce mortality risk for chimpanzees, wolves, and agents: Multiple lines of evidence in a model validation framework," Ecological Modelling, Elsevier, vol. 471(C).
    19. Curk, Te. & Rast, W. & Portas, R. & Kohles, J. & Shatumbu, G. & Cloete, C. & Curk, Ti. & Radchuk, V. & Aschenborn, O. & Melzheimer, J., 2025. "Advantages and disadvantages of using social information for carcass detection–A case study using white-backed vultures," Ecological Modelling, Elsevier, vol. 499(C).
    20. Troost, Christian & Huber, Robert & Bell, Andrew R. & van Delden, Hedwig & Filatova, Tatiana & Le, Quang Bao & Lippe, Melvin & Niamir, Leila & Polhill, J. Gareth & Sun, Zhanli & Berger, Thomas, 2023. "How to keep it adequate: A protocol for ensuring validity in agent-based simulation," EconStor Open Access Articles and Book Chapters, ZBW - Leibniz Information Centre for Economics, vol. 159, pages 1-21.

    More about this item

    Keywords

    ;
    ;
    ;
    ;
    ;
    ;

    Statistics

    Access and download statistics

    Corrections

    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:eee:ecomod:v:520:y:2026:i:c:s0304380026001973. See general information about how to correct material in RePEc.

    If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

    If CitEc recognized a bibliographic reference but did not link an item in RePEc to it, you can help with this form .

    If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your RePEc Author Service profile, as there may be some citations waiting for confirmation.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: Catherine Liu (email available below). General contact details of provider: http://www.journals.elsevier.com/ecological-modelling .

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service. RePEc uses bibliographic data supplied by the respective publishers.